Skip to content
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

✨ feat: gtm loggin user property 추가 #121

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/app/(route)/api/auth/[...auth]/utils/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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,
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/api.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions src/app/api/schema/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface TokenResponse {
accessToken: string;
refreshToken: string;
username: string;
createdAt: string;
/**
* @description
* 100 닉네임 설정 false & 몬스터 생성 false
Expand All @@ -21,5 +22,6 @@ export type Session = Response & {
userInfo: {
memberId?: number;
username?: string;
createdAt?: string;
};
};
1 change: 1 addition & 0 deletions src/app/components/logging/ScreenView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function ScreenView({ name, children, disabled = false }: Props) {

const userProperties = {
userId: user?.id,
userJoinDate: user?.joinDate,
numOfMonsters: totalElements || -1,
lastLoginDate: ensureLoginDate(),
};
Expand Down
15 changes: 12 additions & 3 deletions src/app/hooks/useUserInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Session } from '@api/schema/token';
type User = {
id: number;
name: string;
joinDate: string;
};

const useUserInfo = (session: Session | undefined) => {
Expand All @@ -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<User>('userInfo');
setUser({ name: userInfo?.name || '', id: userInfo?.id || 0 });
setUser({
name: userInfo?.name || '',
id: userInfo?.id || 0,
joinDate: userInfo?.joinDate || '',
});
}, [session]);

useEffect(() => {
Expand Down