diff --git a/adapters/auth/auth.transformer.ts b/adapters/auth/auth.transformer.ts index 9ee43bab..d1ac975b 100644 --- a/adapters/auth/auth.transformer.ts +++ b/adapters/auth/auth.transformer.ts @@ -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, } -} +} \ No newline at end of file diff --git a/adapters/auth/auth.type.ts b/adapters/auth/auth.type.ts index 79b7d2b5..eb4e4987 100644 --- a/adapters/auth/auth.type.ts +++ b/adapters/auth/auth.type.ts @@ -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; } diff --git a/adapters/auth/index.ts b/adapters/auth/index.ts index 825bd208..6fd9d821 100644 --- a/adapters/auth/index.ts +++ b/adapters/auth/index.ts @@ -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 => { +export const getSelf = async (): Promise => { 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 +} \ No newline at end of file diff --git a/components/AppAvatar.vue b/components/AppAvatar.vue new file mode 100644 index 00000000..d87d9cb6 --- /dev/null +++ b/components/AppAvatar.vue @@ -0,0 +1,17 @@ + + + \ No newline at end of file diff --git a/components/AppNavBar.vue b/components/AppNavBar.vue index a20e05b7..ea8a819c 100644 --- a/components/AppNavBar.vue +++ b/components/AppNavBar.vue @@ -11,44 +11,63 @@ + - - - + - diff --git a/components/PopupAssignee.vue b/components/PopupAssignee.vue index a8cea659..1878a01e 100644 --- a/components/PopupAssignee.vue +++ b/components/PopupAssignee.vue @@ -10,12 +10,11 @@ diff --git a/layouts/default.vue b/layouts/default.vue index 956e215f..9298cacf 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -1,7 +1,7 @@ -