Skip to content

Commit

Permalink
feat: 회원탈퇴 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Xvezda committed May 3, 2024
1 parent 76536e5 commit 1c04b72
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions apps/api/src/services/auth/v1/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,6 @@ app.use('*', cors({
}));

app.get('/logout', withPrevUrl, async (c) => {
/*
const url = new URL('https://nid.naver.com/oauth2.0/token');
url.searchParams.append('grant_type', 'delete');
url.searchParams.append('client_id', c.env.OAUTH_CLIENT_ID_NAVER);
url.searchParams.append('client_secret', c.env.OAUTH_CLIENT_SECRET_NAVER);
url.searchParams.append('access_token', user.accessToken);
url.searchParams.append('service_provider', 'NAVER');
const response = await fetch(url);
const result = await response.json() as DeleteTokenRespone;
*/

try {
// access token 갱신 요청으로 이전 토큰을 무효화
const sessionSid = getCookie(c, 'session_sid')!;
Expand Down Expand Up @@ -494,4 +482,27 @@ app.get('/me', withSession, async (c) => {
});
});

app.delete('/me', withSession, async (c) => {
const { user } = c.var.session;

const url = new URL('https://nid.naver.com/oauth2.0/token');
url.searchParams.append('grant_type', 'delete');
url.searchParams.append('client_id', c.env.OAUTH_CLIENT_ID_NAVER);
url.searchParams.append('client_secret', c.env.OAUTH_CLIENT_SECRET_NAVER);
url.searchParams.append('access_token', user.accessToken);
url.searchParams.append('service_provider', 'NAVER');

const response = await fetch(url);
const result = await response.json() as DeleteTokenRespone;

const db = drizzle(c.env.DB);

await db.delete(usersTable)
.where(eq(usersTable.userId, user.userId));

deleteSessionCookies(c);

return c.json(result);
});

export default app;

0 comments on commit 1c04b72

Please sign in to comment.