Skip to content

Commit

Permalink
feat: 미로그인시 에러 catch (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
darae07 authored Jul 5, 2023
1 parent eea4d65 commit 4e868a9
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions src/app/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,36 @@ import { UserInfoResponse } from '~/types/user';
import { ROUTE_COOKIE_KEYS } from '~/utils/route/route';

export async function GET(request: NextRequest) {
const cookieStore = cookies();
const accessToken = cookieStore.get(AUTH_COOKIE_KEYS.accessToken)?.value;
if (accessToken) {
// TO DO: BE 도메인 정상화 이후 복원 + privateApi로 변경
const { userProfileDto } = await privateApi.get<UserInfoResponse>(`/user/profile`);
const { characterType, communityIds } = userProfileDto;
try {
const cookieStore = cookies();
const accessToken = cookieStore.get(AUTH_COOKIE_KEYS.accessToken)?.value;
if (accessToken) {
// TO DO: BE 도메인 정상화 이후 복원 + privateApi로 변경
const { userProfileDto } = await privateApi.get<UserInfoResponse>(`/user/profile`);
const { characterType, communityIds } = userProfileDto;

const redirectUri = request.cookies.get(ROUTE_COOKIE_KEYS.redirectUri)?.value;
if (redirectUri?.includes('invitation')) {
const response = NextResponse.redirect(new URL(redirectUri, request.url));
response.cookies.delete(ROUTE_COOKIE_KEYS.redirectUri);
return response;
}

if (characterType) {
if (redirectUri) {
const redirectUri = request.cookies.get(ROUTE_COOKIE_KEYS.redirectUri)?.value;
if (redirectUri?.includes('invitation')) {
const response = NextResponse.redirect(new URL(redirectUri, request.url));
response.cookies.delete(ROUTE_COOKIE_KEYS.redirectUri);
return response;
}

return communityIds.length > 0
? NextResponse.redirect(new URL(`/planet/${communityIds[0]}`, request.url))
: NextResponse.redirect(new URL('/planet', request.url));
if (characterType) {
if (redirectUri) {
const response = NextResponse.redirect(new URL(redirectUri, request.url));
response.cookies.delete(ROUTE_COOKIE_KEYS.redirectUri);
return response;
}

return communityIds.length > 0
? NextResponse.redirect(new URL(`/planet/${communityIds[0]}`, request.url))
: NextResponse.redirect(new URL('/planet', request.url));
}
return NextResponse.redirect(new URL('/onboarding', request.url));
}
return NextResponse.redirect(new URL('/onboarding', request.url));
return NextResponse.redirect(new URL('/auth/signin', request.url));
} catch (e) {
return NextResponse.redirect(new URL('/auth/signin', request.url));
}
return NextResponse.redirect(new URL('/auth/signin', request.url));
}

0 comments on commit 4e868a9

Please sign in to comment.