261103_03_ENH: 공유 인증 사용자 정보 동기화 및 프로젝트 접근 전환 개선
This commit is contained in:
22
src/app/api/auth/[[...slug]]/route.ts
Normal file
22
src/app/api/auth/[[...slug]]/route.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { errorToResponse } from "@kri/common/http";
|
||||
import { createContactApi } from "@/lib/http-server";
|
||||
import {isLoginUser} from "@/lib/auth-user";
|
||||
|
||||
export async function GET(_request: Request, context: { params: Promise<{ slug?: string[] }> }) {
|
||||
const { slug = [] } = await context.params;
|
||||
if (slug.length !== 1 || slug[0] !== "my-info")
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404, headers: { "Cache-Control": "no-store" } });
|
||||
try {
|
||||
const api = await createContactApi();
|
||||
const user = await api.get<unknown>("/auth/my-info", { cache: "no-store" });
|
||||
if (!isLoginUser(user)) {
|
||||
return NextResponse.json({ message: "Invalid user response" }, { status: 502, headers: { "Cache-Control": "no-store" } });
|
||||
}
|
||||
return NextResponse.json({ userId: user.userId, userName: user.userName, userCmpn: user.userCmpn, userTeam: user.userTeam, userRole: user.userRole }, { headers: { "Cache-Control": "no-store" } });
|
||||
} catch (error) {
|
||||
const response = errorToResponse(error);
|
||||
response.headers.set("Cache-Control", "no-store");
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user