NextAuth
ํ์ตํค์๋
์ค์น ๋ฐ ์ธํ
Next Auth
์ค์น ๋ฐ ์ธํ
Next14 ๋ฒ์ ์ ํ์ฌ ํธํ์ฑ ๋ฌธ์ ์์ (24.06.13 ๊ธฐ์ค)
๐ ๊ณต์๋ฌธ์ ์ฐธ๊ณ
npm install next-auth@beta
ํฐ๋ฏธ๋์ ์
๋ ฅํด์ ๋์จ ๋ฌธ์๋ฅผ ํ๊ฒฝ๋ณ์๋ก ์ง์
openssl rand -base64 33
AUTH_SECRET= ํ๊ฒฝ๋ณ์์ง์
src/auth.ts
import NextAuth from 'next-auth';
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [],
});
app/api/auth/[...nextauth]/route.ts
import { handlers } from '@/auth'; // Referring to the auth.ts we just created
export const { GET, POST } = handlers;
src/middleware.ts
๐จ ๋ฐฐํฌ๋ฅผ ์ํด bulid ํ๋ฉด ํด๋น ํ์ผ error
export { auth as middleware } from '@/auth';
ํด๋น ์ฝ๋๋ฅผ ์ฌ์ฉ๋ก ๋ณ๊ฒฝ ํด์ผํจ
import { NextRequest, NextResponse } from 'next/server';
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};
export async function middleware(request: NextRequest) {
return NextResponse.next();
}
Last updated