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: 미로그인시 에러 catch #244

Merged
merged 1 commit into from
Jul 5, 2023
Merged
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
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));
}