src/app/api/auth/[...nextauth]/route.ts
Type error: Route "src/app/api/auth/[...nextauth]/route.ts" does not match the required types of a Next.js Route.
"handler" is not a valid Route export field.
error Command failed with exit code 1.
authOptions와 handler를 함께 export해서 발생하는 문제
yarn dev 에서는 문제가 발생 안하지만 yarn build시 에러가 발생
import NextAuth from 'next-auth'
import GoogleProvider from 'next-auth/providers/google'
export const authOptions = {
// Configure one or more authentication providers
providers: [
GoogleProvider({
clientId: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID ?? '',
clientSecret: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_SECRET ?? '',
}),
],
}
const handler = NextAuth(authOptions)
export const GET = handler
export const POST = handler
authOptions와 handler를 파일을 분리해서 export 진행
// 파일 위치
// src/app/api/auth/[...nextauth]/options.ts
import GoogleProvider from 'next-auth/providers/google'
export const authOptions = {
// Configure one or more authentication providers
providers: [
GoogleProvider({
clientId: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID ?? '',
clientSecret: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_SECRET ?? '',
}),
],
}
// 파일 위치
// src/app/api/auth/[...nextauth]/route.ts
import NextAuth from 'next-auth'
import { authOptions } from './options'
const handler = NextAuth(authOptions)
export const GET = handler
export const POST = handler