From e3b12a2f3fe3fa2e144cdbef5c3b0f1a1544342c Mon Sep 17 00:00:00 2001 From: yoonseokgyu Date: Sat, 7 Sep 2024 16:04:55 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20gtm=20loggin=20user=20prope?= =?UTF-8?q?rty=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - userJoinDate 추가 --- .../(route)/api/auth/[...auth]/utils/redirect.ts | 14 ++++++++++++-- src/app/api/api.constants.ts | 2 +- src/app/api/schema/token.ts | 2 ++ src/app/components/logging/ScreenView.tsx | 1 + src/app/hooks/useUserInfo.ts | 15 ++++++++++++--- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/app/(route)/api/auth/[...auth]/utils/redirect.ts b/src/app/(route)/api/auth/[...auth]/utils/redirect.ts index d4af15a..1132e07 100644 --- a/src/app/(route)/api/auth/[...auth]/utils/redirect.ts +++ b/src/app/(route)/api/auth/[...auth]/utils/redirect.ts @@ -7,7 +7,14 @@ import { encrypt } from './crypto'; import tokenPrefix from './token-prefix'; const redirectResponse = ( - { code, username, accessToken, refreshToken, memberId }: TokenResponse, + { + code, + username, + accessToken, + refreshToken, + memberId, + createdAt, + }: TokenResponse, secret: string, ) => { const destinationUrl = @@ -34,7 +41,10 @@ const redirectResponse = ( }, { key: 'userInfo', - value: encrypt(JSON.stringify({ memberId, username }), secret), + value: encrypt( + JSON.stringify({ memberId, username, createdAt }), + secret, + ), proteced: true, }, ], diff --git a/src/app/api/api.constants.ts b/src/app/api/api.constants.ts index 022eced..d1ce3f4 100644 --- a/src/app/api/api.constants.ts +++ b/src/app/api/api.constants.ts @@ -19,7 +19,7 @@ export const API_URLS = { REFRESH_TOKEN: `${MEMBER_BASE}/token/refresh`, USER_NICKNAME: `${MEMBER_BASE}/my`, GET_TOKEN: { - kakao: `${MEMBER_BASE}/login/kakao`, + kakao: `${MEMBER_BASE}/login/kakao/test`, }, }, }, diff --git a/src/app/api/schema/token.ts b/src/app/api/schema/token.ts index e444b64..8febffa 100644 --- a/src/app/api/schema/token.ts +++ b/src/app/api/schema/token.ts @@ -3,6 +3,7 @@ export interface TokenResponse { accessToken: string; refreshToken: string; username: string; + createdAt: string; /** * @description * 100 닉네임 설정 false & 몬스터 생성 false @@ -21,5 +22,6 @@ export type Session = Response & { userInfo: { memberId?: number; username?: string; + createdAt?: string; }; }; diff --git a/src/app/components/logging/ScreenView.tsx b/src/app/components/logging/ScreenView.tsx index 66ea7f2..1cb99e7 100644 --- a/src/app/components/logging/ScreenView.tsx +++ b/src/app/components/logging/ScreenView.tsx @@ -40,6 +40,7 @@ function ScreenView({ name, children, disabled = false }: Props) { const userProperties = { userId: user?.id, + userJoinDate: user?.joinDate, numOfMonsters: totalElements || -1, lastLoginDate: ensureLoginDate(), }; diff --git a/src/app/hooks/useUserInfo.ts b/src/app/hooks/useUserInfo.ts index 675eb91..40fe0a8 100644 --- a/src/app/hooks/useUserInfo.ts +++ b/src/app/hooks/useUserInfo.ts @@ -11,6 +11,7 @@ import { Session } from '@api/schema/token'; type User = { id: number; name: string; + joinDate: string; }; const useUserInfo = (session: Session | undefined) => { @@ -20,15 +21,23 @@ const useUserInfo = (session: Session | undefined) => { if (!session || session.status === 'unauthenticated') return; const { - userInfo: { username, memberId }, + userInfo: { username, memberId, createdAt }, } = session; if (!getSessionItem('userInfo')) { - setSessionItem('userInfo', { name: username, id: memberId }); + setSessionItem('userInfo', { + name: username, + id: memberId, + joinDate: createdAt, + }); } const userInfo = getSessionItem('userInfo'); - setUser({ name: userInfo?.name || '', id: userInfo?.id || 0 }); + setUser({ + name: userInfo?.name || '', + id: userInfo?.id || 0, + joinDate: userInfo?.joinDate || '', + }); }, [session]); useEffect(() => {