fix(gateway): accept Kakao already-registered response

This commit is contained in:
2026-08-08 12:51:45 +00:00
parent 5c0aac5561
commit 31fcaa2c1c
4 changed files with 63 additions and 4 deletions
+12 -2
View File
@@ -25,6 +25,11 @@ export interface KakaoUserInfo {
kakaoAccount: KakaoAccountInfo;
}
export interface KakaoSignupResult {
id?: string;
alreadyRegistered: boolean;
}
const buildForm = (params: Record<string, string>): URLSearchParams => {
const form = new URLSearchParams();
for (const [key, value] of Object.entries(params)) {
@@ -106,19 +111,24 @@ export class KakaoOAuthClient {
return parseToken(payload);
}
async signup(accessToken: string): Promise<{ id?: string; msg?: string }> {
async signup(accessToken: string): Promise<KakaoSignupResult> {
const response = await fetch(new URL('/v1/user/signup', this.apiHost), {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
const payload = (await response.json()) as Record<string, unknown>;
if (!response.ok && payload.code === -102 && payload.msg === 'already registered') {
return {
alreadyRegistered: true,
};
}
if (!response.ok) {
throw new Error(`Kakao signup error: ${JSON.stringify(payload)}`);
}
return {
id: payload.id ? String(payload.id) : undefined,
msg: payload.msg ? String(payload.msg) : undefined,
alreadyRegistered: false,
};
}
+1 -1
View File
@@ -253,7 +253,7 @@ export const appRouter = router({
const tokenIssuedAt = new Date();
const signupResult = await ctx.kakaoClient.signup(token.accessToken);
const alreadyRegisteredWithKakao = !signupResult.id && signupResult.msg === 'already registered';
const alreadyRegisteredWithKakao = !signupResult.id && signupResult.alreadyRegistered;
if (!signupResult.id && !alreadyRegisteredWithKakao) {
throw new TRPCError({
code: 'BAD_REQUEST',