Add GitHub provider

This commit is contained in:
Cédric FAMIBELLE-PRONZOLA
2022-10-28 08:28:35 +04:00
parent 4e79513eca
commit 10a12ea8f5
4 changed files with 17 additions and 2 deletions
+6
View File
@@ -43,6 +43,12 @@ const PROVIDERS = [
title: 'Twitter', title: 'Twitter',
width: 56, width: 56,
height: 46 height: 46
},
{
id: 'github',
title: 'GitHub',
width: 52,
height: 51
} }
] ]
+4 -1
View File
@@ -2,8 +2,11 @@ import PropTypes from 'prop-types'
import Link from 'next/link' import Link from 'next/link'
import Image from 'next/image' import Image from 'next/image'
import {signIn} from 'next-auth/react' import {signIn} from 'next-auth/react'
import {useTheme} from '@mui/material/styles'
export default function LoginProvider({id, title, width, height, callbackUrl}) { export default function LoginProvider({id, title, width, height, callbackUrl}) {
const theme = useTheme()
const hanleClick = event => { const hanleClick = event => {
event.preventDefault() event.preventDefault()
signIn(id, { signIn(id, {
@@ -18,7 +21,7 @@ export default function LoginProvider({id, title, width, height, callbackUrl}) {
width={width} width={width}
height={height} height={height}
alt={title} alt={title}
src={`/images/${id}.svg`} src={`/images/${id === 'github' ? `${id}-${theme.palette.mode}` : id}.svg`}
onClick={hanleClick} onClick={hanleClick}
/> />
</Link> </Link>
+1
View File
@@ -73,6 +73,7 @@
"CredentialsProvider", "CredentialsProvider",
"TwitterProvider", "TwitterProvider",
"GoogleProvider", "GoogleProvider",
"GitHubProvider",
"NextAuth" "NextAuth"
] ]
} }
+6 -1
View File
@@ -2,6 +2,7 @@ import NextAuth from 'next-auth'
import CredentialsProvider from 'next-auth/providers/credentials' import CredentialsProvider from 'next-auth/providers/credentials'
import TwitterProvider from 'next-auth/providers/twitter' import TwitterProvider from 'next-auth/providers/twitter'
import GoogleProvider from 'next-auth/providers/google' import GoogleProvider from 'next-auth/providers/google'
import GitHubProvider from 'next-auth/providers/github'
import axios from 'axios' import axios from 'axios'
const options = { const options = {
@@ -36,6 +37,10 @@ const options = {
GoogleProvider({ GoogleProvider({
clientId: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID, clientId: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID,
clientSecret: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_SECRET clientSecret: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_SECRET
}),
GitHubProvider({
clientId: process.env.NEXT_PUBLIC_GITHUB_CLIENT_ID,
clientSecret: process.env.NEXT_PUBLIC_GITHUB_CLIENT_SECRET
}) })
], ],
secret: process.env.NEXT_PUBLIC_JWT_SECRET, secret: process.env.NEXT_PUBLIC_JWT_SECRET,
@@ -51,7 +56,7 @@ const options = {
url = `${process.env.NEXT_PUBLIC_API_URL}/auth/${account.provider}/callback?access_token=${account?.oauth_token}&access_secret=${account?.oauth_token_secret}` url = `${process.env.NEXT_PUBLIC_API_URL}/auth/${account.provider}/callback?access_token=${account?.oauth_token}&access_secret=${account?.oauth_token_secret}`
} }
if (account.provider === 'google') { if (account.provider === 'google' || account.provider === 'github') {
url = `${process.env.NEXT_PUBLIC_API_URL}/auth/${account.provider}/callback?access_token=${account?.access_token}` url = `${process.env.NEXT_PUBLIC_API_URL}/auth/${account.provider}/callback?access_token=${account?.access_token}`
} }