npm i next-auth
pages/api/auth/[nextauth].js 파일생성
import NextAuth from "next-auth"; import GithubProvider from "next-auth/providers/github"; export const authOptions = { providers: [ GithubProvider({ clientId: 'Github에서 발급받은ID', clientSecret: 'Github에서 발급받은Secret', }), ], secret : 'jwt생성시쓰는암호' }; export default NextAuth(authOptions);
NextAuth.js
Authentication for Next.js
next-auth.js.org
시크릿키 잊지말고 입력해야함
"use client";
import { useSession, signIn, signOut } from "next-auth/react";
export default function LgoinBtn() {
return (
<button
onClick={() => {
signIn();
}}>
로그인
</button>
);
}
signIn 이라는 라이브러리함수쓰면 자동으로 로그인페이지 만들어짐
let session = await getServerSession(authOptions);
console.log(session);
{
user: {
name: '깃허브닉넴',
email: '이멜@gmail.com',
image: '유저프사'
}
}
깃허브에서 시크릿키 발급받는방법
'프로그래밍 > NextJS' 카테고리의 다른 글
nextjs 페이지이동 Link,useRouter (0) | 2024.01.05 |
---|---|
nextjs에서 prsima, planetScale 연결 (1) | 2024.01.04 |
nextjs aws를 이용한 이미지 업로드 (0) | 2023.12.14 |
next js) 서버컴포넌트,클라이언트컴포넌트,deduplication (1) | 2023.12.05 |
Next js 설치 및 라우팅 하는 법 (1) | 2023.12.05 |