-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Github SSO #191
base: main
Are you sure you want to change the base?
Github SSO #191
Changes from all commits
2496449
a22fdbf
7fdee05
d421b4a
066a1d0
8686920
16f0fe1
11a4995
8e5b772
f4b7d4c
25f9d17
53e7287
98ff8be
04593b1
1c721a0
fa83d9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,34 +16,74 @@ onMounted(() => { | |
<template> | ||
<div class="dark:text-zinc-200 dark:ring-white/10 pl-4"> | ||
<BaseButton | ||
v-if="!isLoggedIn" href="/login" color="primary" class="font-medium hidden md:block" | ||
v-if="!isLoggedIn" | ||
href="/login" | ||
color="primary" | ||
class="font-medium hidden md:block" | ||
@click="setUrl()" | ||
> | ||
Log In | ||
</BaseButton> | ||
<BaseButton | ||
v-if="!isLoggedIn" href="/login" color="primary" class="font-medium block md:hidden" size="sm" | ||
v-if="!isLoggedIn" | ||
href="/login" | ||
color="primary" | ||
class="font-medium block md:hidden" | ||
size="sm" | ||
@click="setUrl()" | ||
> | ||
Log In | ||
</BaseButton> | ||
<div v-else class="flex gap-2 items-center"> | ||
<Menu as="div" class="relative inline-block text-left"> | ||
<div | ||
v-else | ||
class="flex gap-2 items-center" | ||
> | ||
<Menu | ||
as="div" | ||
class="relative inline-block text-left" | ||
> | ||
<div> | ||
<MenuButton | ||
class="inline-flex items-center w-full justify-center gap-x-1.5 rounded-full text-sm font-semibold text-verse-900 dark:text-verse-100 shadow-sm ring-gray-300 hover:bg-gray-50" | ||
class="inline-flex relative items-center w-full justify-center gap-x-1.5 rounded-full text-sm font-semibold text-verse-900 dark:text-verse-100 shadow-sm ring-gray-300 hover:bg-gray-50" | ||
> | ||
<div v-if="avatarUrl"> | ||
<img class="w-10 aspect-square rounded-full" :src="avatarUrl"> | ||
<template v-if="user?.provider === 'github'"> | ||
<img | ||
class="w-10 aspect-square rounded-full" | ||
:src="`https://github.com/${user?.external_identifier}.png`" | ||
> | ||
</template> | ||
<template v-else> | ||
<div v-if="avatarUrl"> | ||
<img | ||
class="w-10 aspect-square rounded-full" | ||
:src="avatarUrl" | ||
> | ||
</div> | ||
</template> | ||
Comment on lines
+47
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification GitHub SSO avatar handling implemented correctly, but error cases need attention The codebase analysis confirms that the GitHub SSO avatar handling has been implemented as intended. The <template v-if="user?.provider === 'github'">
<img
class="w-10 aspect-square rounded-full"
:src="`https://github.com/${user?.external_identifier}.png`"
>
</template> However, the initial concern about error handling remains valid. To address potential error cases, consider the following recommendations:
const avatarUrl = computed(() => {
if (user.value?.avatar_url) {
return user.value.avatar_url
} else if (rawUser.value?.github_username) {
return `https://github.com/${rawUser.value.github_username}.png`
} else if (user.value?.provider === 'github' && user.value?.external_identifier) {
return `https://github.com/${user.value.external_identifier}.png`
} else {
return '/path/to/fallback/avatar.png' // Provide a fallback avatar
}
})
<img
class="w-10 aspect-square rounded-full"
:src="`https://github.com/${user?.external_identifier}.png`"
@error="handleAvatarError"
alt="User avatar"
> Add a method to handle avatar loading errors: function handleAvatarError(event: Event) {
const img = event.target as HTMLImageElement;
img.src = '/path/to/fallback/avatar.png'; // Set a fallback avatar
} These changes will improve the robustness of the avatar handling and provide a better user experience in case of errors. 🔗 Analysis chainGitHub SSO avatar handling implemented, but error cases need attention The addition of conditional rendering for user avatars, especially the GitHub-specific handling, is a good step towards implementing the GitHub SSO functionality. However, as per the PR objectives, we need to address potential error cases. Consider adding error handling for scenarios where:
To ensure we're handling all potential avatar sources correctly, let's verify the user object structure: Correction Needed: Shell script errors detected during user object verification The previous verification script encountered errors due to unrecognized file types and a typo in the directory path. Please use the corrected script below to verify the structure of the Further Verification Needed: Unable to locate The previous attempts to verify the 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify the structure of the user object in auth-related files
# Test: Search for user object definitions or usages
rg --type vue --type ts 'user\s*:\s*\{' packages/frontendmu-nuxt
Length of output: 197 Script: # Description: Verify the structure of the user object in auth-related files
# Corrected Test: Search for user object definitions or usages in .vue and .ts files
rg 'user\s*:\s*\{' packages/frontendmu-nuxt --glob '*.vue' --glob '*.ts'
Length of output: 74 Script: # Description: Broad search for any occurrences of 'user' in .vue and .ts files
rg 'user' packages/frontendmu-nuxt --glob '*.vue' --glob '*.ts'
Length of output: 17940 Script: # Description: Use ast-grep to find user object declarations in .vue and .ts files
ast-grep --lang typescript --pattern $'const user: $_Type = { $$$ }' packages/frontendmu-nuxt
Length of output: 94 |
||
<!-- Provider Hint --> | ||
<div class="absolute bottom-0 right-0 bg-white rounded-full"> | ||
<div v-if="user?.provider === 'default'"> | ||
<Icon | ||
class="block w-3 h-3 p-0.5 text-black" | ||
name="fluent:animal-rabbit-24-regular" | ||
/> | ||
</div> | ||
<div v-else> | ||
<Icon | ||
:name="`carbon:logo-${user?.provider}`" | ||
class="block w-3 h-3 p-0.5 text-black" | ||
/> | ||
</div> | ||
</div> | ||
<!-- <ChevronDownIcon class="-mr-1 h-5 w-5 text-gray-400" aria-hidden="true" /> --> | ||
</MenuButton> | ||
</div> | ||
|
||
<transition | ||
enter-active-class="transition ease-out duration-100" | ||
enter-from-class="transform opacity-0 scale-95" enter-to-class="transform opacity-100 scale-100" | ||
leave-active-class="transition ease-in duration-75" leave-from-class="transform opacity-100 scale-100" | ||
enter-from-class="transform opacity-0 scale-95" | ||
enter-to-class="transform opacity-100 scale-100" | ||
leave-active-class="transition ease-in duration-75" | ||
leave-from-class="transform opacity-100 scale-100" | ||
leave-to-class="transform opacity-0 scale-95" | ||
> | ||
<MenuItems | ||
|
@@ -53,15 +93,17 @@ onMounted(() => { | |
<MenuItem v-slot="{ active }"> | ||
<NuxtLink | ||
href="/user/me" | ||
class="block px-4 py-2 text-sm" :class="[active ? 'bg-gray-400/10 text-verse-900 dark:text-verse-100' : 'text-verse-900 dark:text-verse-100']" | ||
class="block px-4 py-2 text-sm" | ||
:class="[active ? 'bg-gray-400/10 text-verse-900 dark:text-verse-100' : 'text-verse-900 dark:text-verse-100']" | ||
> | ||
My | ||
Profile | ||
</NuxtLink> | ||
</MenuItem> | ||
<MenuItem v-slot="{ active }"> | ||
<NuxtLink | ||
class="block px-4 py-2 text-sm cursor-pointer" :class="[active ? 'bg-gray-400/10 text-verse-900 dark:text-verse-100' : 'text-verse-900 dark:text-verse-100']" | ||
class="block px-4 py-2 text-sm cursor-pointer" | ||
:class="[active ? 'bg-gray-400/10 text-verse-900 dark:text-verse-100' : 'text-verse-900 dark:text-verse-100']" | ||
@click="logout()" | ||
> | ||
Logout | ||
|
@@ -71,7 +113,10 @@ onMounted(() => { | |
<div class="text-verse-900 dark:text-verse-100 p-4 text-sm"> | ||
<div class="flex flex-col items-center justify-center gap-2"> | ||
<div v-if="avatarUrl"> | ||
<img class="w-16 aspect-square rounded-full" :src="avatarUrl"> | ||
<img | ||
class="w-16 aspect-square rounded-full" | ||
:src="avatarUrl" | ||
> | ||
</div> | ||
|
||
{{ user?.full_name }} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Refactor 'oAuthLogin' function to eliminate code duplication
The
oAuthLogin
function contains repetitive code for each provider. Consider refactoring to eliminate duplication and improve maintainability. You can use a mapping of providers to their respective paths and handle the redirect logic more concisely.Apply this diff to refactor the function:
📝 Committable suggestion