지금까지 내용 커밋
This commit is contained in:
34
page/src/app/api/auth/[...nextauth]/route.ts
Normal file
34
page/src/app/api/auth/[...nextauth]/route.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import NextAuth, { NextAuthOptions } from "next-auth";
|
||||
import DiscordProvider from "next-auth/providers/discord";
|
||||
|
||||
export const authOptions: NextAuthOptions = {
|
||||
providers: [
|
||||
DiscordProvider({
|
||||
clientId: process.env.DISCORD_CLIENT_ID as string,
|
||||
clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
|
||||
// 🌟 핵심: 로그인할 때 유저의 기본 정보(identify)와 서버 목록(guilds) 권한을 같이 가져옵니다!
|
||||
authorization: { params: { scope: "identify email guilds" } },
|
||||
}),
|
||||
],
|
||||
session: {
|
||||
strategy: "jwt",
|
||||
},
|
||||
callbacks: {
|
||||
// 디스코드에서 받은 토큰(accessToken)을 우리 세션에 저장해두는 로직
|
||||
async jwt({ token, account }) {
|
||||
if (account) {
|
||||
token.accessToken = account.access_token;
|
||||
}
|
||||
return token;
|
||||
},
|
||||
async session({ session, token }: any) {
|
||||
session.accessToken = token.accessToken;
|
||||
return session;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const handler = NextAuth(authOptions);
|
||||
|
||||
// App Router 환경에서는 GET과 POST 메서드를 둘 다 내보내야 합니다.
|
||||
export { handler as GET, handler as POST };
|
||||
Reference in New Issue
Block a user