generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Auth/integration #190
Open
pallabez
wants to merge
3
commits into
develop
Choose a base branch
from
auth/integration
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Auth/integration #190
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
import { type User } from '~/interfaces/User' | ||
import { type SelfInfo } from './auth.type' | ||
import { transformUser } from '~/adapters/user.transformer' | ||
|
||
export const transformSelfInfoFromApi = (userInfo: any): { info: SelfInfo, user: User } => { | ||
const info = { | ||
userId: userInfo?.id, | ||
export const transformSelfInfoFromApi = (userInfo: any): SelfInfo => { | ||
return { | ||
...transformUser(userInfo), | ||
status: userInfo?.status, | ||
incompleteUserDetails: userInfo?.incompleteUserDetails, | ||
roles: { | ||
archived: userInfo?.roles?.archived, | ||
member: userInfo?.roles?.member | ||
member: userInfo?.roles?.member, | ||
}, | ||
status: userInfo?.status, | ||
incompleteUserDetails: userInfo?.incompleteUserDetails | ||
} | ||
|
||
const user = { | ||
id: userInfo?.id, | ||
username: userInfo?.username, | ||
firstName: userInfo?.first_name, | ||
lastName: userInfo?.last_name, | ||
githubId: userInfo?.github_id, | ||
githubDisplayName: userInfo?.github_display_name, | ||
avatarUrl: userInfo?.picture?.url | ||
} | ||
} | ||
|
||
export const transformGoalTokenFromApi = (response: any): { | ||
token: { | ||
exp: number, | ||
access: string, | ||
}, | ||
id: string, | ||
} => { | ||
return { | ||
info, | ||
user | ||
token: { | ||
exp: response?.user?.token?.exp, | ||
access: response?.user?.token?.access, | ||
}, | ||
id: response?.user?.id, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
export interface SelfInfo { | ||
userId: string | ||
id: string | ||
displayName: string | ||
username: string | ||
firstName: string | ||
lastName: string | ||
avatar: string | ||
initials: string | ||
roles: { | ||
member: boolean | ||
archived: boolean | ||
} | ||
status: string | ||
incompleteUserDetails: boolean | ||
archived: boolean | undefined; | ||
member: boolean | undefined; | ||
}; | ||
status: string | undefined; | ||
incompleteUserDetails: boolean | undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,28 @@ | ||
import axios, { isAxiosError } from 'axios' | ||
import { transformSelfInfoFromApi } from './auth.transformer' | ||
import { type ApiResponse } from '~/interfaces/ApiResponse' | ||
import { type User } from '~/interfaces/User' | ||
import axios from 'axios' | ||
import { transformSelfInfoFromApi, transformGoalTokenFromApi } from './auth.transformer' | ||
import { type SelfInfo } from './auth.type' | ||
import { | ||
type ErrorApiForbidden, | ||
type ErrorApiUnauthorized, | ||
type ErrorApiUnavailable, | ||
type ErrorApiNotFound, | ||
type ErrorApiBase | ||
} from '~/interfaces/ErrorApi' | ||
import { getConfig } from '~/config' | ||
|
||
type GetSelfResponse = ApiResponse< | ||
{ | ||
user: User | ||
info: SelfInfo | ||
}, | ||
ErrorApiForbidden | ErrorApiUnauthorized | ErrorApiUnavailable | ErrorApiNotFound | ErrorApiBase | ||
> | ||
|
||
export const getSelf = async (): Promise<GetSelfResponse> => { | ||
export const getSelf = async (): Promise<SelfInfo> => { | ||
const config = getConfig(); | ||
const response: GetSelfResponse = await axios | ||
const response = await axios | ||
.get(`${config.RDS_API}/users/self/`, { withCredentials: true }) | ||
.then(res => ({ data: transformSelfInfoFromApi(res.data) })) | ||
.catch((error) => { | ||
if (isAxiosError(error)) { | ||
if (error.response != null) { | ||
const responseData = error.response.data | ||
return { | ||
error: { | ||
status: responseData.statusCode, | ||
error: responseData.error, | ||
message: responseData.message | ||
} | ||
} | ||
} | ||
} | ||
throw error // or Log here | ||
}) | ||
.then(res => transformSelfInfoFromApi(res.data)) | ||
|
||
return response | ||
} | ||
|
||
export const getGoalApiCredentials = async (): Promise<{ | ||
token: { | ||
exp: number, | ||
access: string, | ||
}, | ||
id: string, | ||
}> => { | ||
const config = getConfig(); | ||
const response = await axios | ||
.get(`${config.RDS_API}/goals/token/`, { withCredentials: true }) | ||
.then(res => transformGoalTokenFromApi(res.data)) | ||
|
||
return response | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<template> | ||
<v-avatar v-if="props.avatar" v-bind="props.vBind"> | ||
<v-img :src="props.avatar" /> | ||
</v-avatar> | ||
<v-avatar v-else color="indigo" v-bind="props.vBind"> | ||
{{ props.initials }} | ||
</v-avatar> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const props = defineProps({ | ||
avatar: String, | ||
initials: String, | ||
vBind: Object, | ||
}); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,44 +11,63 @@ | |
</ul> | ||
|
||
<v-spacer></v-spacer> | ||
<template v-if="isUserLoading"> | ||
Loading... | ||
</template> | ||
|
||
<nuxt-link :href="LOGIN"> | ||
<button class="login"> | ||
<span class="login__text">Sign In With GitHub</span> | ||
<img class="login__image" src="~/assets/github.png" alt="GitHub Icon" height="15px" width="15px"> | ||
</button> | ||
</nuxt-link> | ||
<template v-else> | ||
<v-menu v-if="!!props.user"> | ||
<template v-slot:activator="{ props: activator }"> | ||
<div v-bind="activator" class="user-detail"> | ||
<span class="username"> | ||
Hello, {{ props.user.firstName || props.user.username }} | ||
</span> | ||
<AppAvatar | ||
:avatar="props.user.avatar" | ||
:initials="props.user.initials" | ||
/> | ||
</div> | ||
</template> | ||
</v-menu> | ||
|
||
<nuxt-link v-else :href="LOGIN"> | ||
<button class="login"> | ||
<span class="login__text">Sign In With GitHub</span> | ||
<img class="login__image" src="~/assets/github.png" alt="GitHub Icon" height="15px" width="15px"> | ||
</button> | ||
</nuxt-link> | ||
</template> | ||
</v-container> | ||
</v-app-bar> | ||
</template> | ||
|
||
<script> | ||
<script setup lang="ts"> | ||
import { getConfig } from '~/config' | ||
import type { SelfInfo } from '~/adapters/auth/auth.type'; | ||
import type { PropType } from 'nuxt/dist/app/compat/capi'; | ||
|
||
const props = defineProps({ | ||
user: Object as PropType<SelfInfo | null>, | ||
isUserLoading: Boolean, | ||
}) | ||
|
||
const isClicked = ref(false); | ||
const LINKS = [ | ||
{ name: 'Welcome', link: 'https://welcome.realdevsquad.com' }, | ||
{ name: 'Events', link: 'https://www.realdevsquad.com/events.html' }, | ||
{ name: 'Members', link: 'https://members.realdevsquad.com/' }, | ||
{ name: 'Crypto', link: 'https://crypto.realdevsquad.com/' }, | ||
{ name: 'Status', link: 'https://status.realdevsquad.com/' } | ||
] | ||
Comment on lines
+55
to
+61
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. These constants can be moved to constants file. |
||
const LOGIN = `${getConfig().RDS_API}/auth/github/login`; | ||
|
||
export default { | ||
name: 'AppNavBar', | ||
data() { | ||
return { | ||
isClicked: false, | ||
LINKS: [ | ||
{ name: 'Welcome', link: 'https://welcome.realdevsquad.com' }, | ||
{ name: 'Events', link: 'https://www.realdevsquad.com/events.html' }, | ||
{ name: 'Members', link: 'https://members.realdevsquad.com/' }, | ||
{ name: 'Crypto', link: 'https://crypto.realdevsquad.com/' }, | ||
{ name: 'Status', link: 'https://status.realdevsquad.com/' } | ||
], | ||
LOGIN: `${getConfig().RDS_API}/auth/github/login` | ||
} | ||
}, | ||
methods: { | ||
toggleClicked(value) { | ||
this.isClicked = !value | ||
}, | ||
redirectLogin() { | ||
window.location.href = this.LOGIN | ||
} | ||
} | ||
function toggleClicked(value: boolean) { | ||
isClicked.value = !value | ||
} | ||
function redirectLogin() { | ||
window.location.href = LOGIN | ||
} | ||
|
||
</script> | ||
|
||
<style scoped> | ||
|
@@ -95,4 +114,14 @@ export default { | |
.login__image { | ||
margin-left: 6px; | ||
} | ||
|
||
.user-detail { | ||
cursor: pointer; | ||
} | ||
|
||
.username { | ||
font-weight: 700; | ||
font-size: 1rem; | ||
margin-right: 5px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { useAuthStore } from "~/store/auth" | ||
|
||
export default defineNuxtRouteMiddleware((to, from) => { | ||
const authStore = useAuthStore(); | ||
|
||
if (!authStore.user) { | ||
authStore.signin(); | ||
} | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not catching errors?