Add Twitter provider to connect
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import NextAuth from 'next-auth'
|
||||
import CredentialsProvider from 'next-auth/providers/credentials'
|
||||
import TwitterProvider from 'next-auth/providers/twitter'
|
||||
import axios from 'axios'
|
||||
|
||||
const options = {
|
||||
@@ -26,6 +27,10 @@ const options = {
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
}
|
||||
}),
|
||||
TwitterProvider({
|
||||
clientId: process.env.NEXT_PUBLIC_TWITTER_API_KEY,
|
||||
clientSecret: process.env.NEXT_PUBLIC_TWITTER_API_KEY_SECRET
|
||||
})
|
||||
],
|
||||
secret: process.env.NEXT_PUBLIC_JWT_SECRET,
|
||||
@@ -35,9 +40,14 @@ const options = {
|
||||
callbacks: {
|
||||
async jwt({token, user, account}) {
|
||||
if (user) {
|
||||
const response = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_API_URL}/auth/${account.provider}/callback?access_token=${account?.accessToken}`
|
||||
)
|
||||
let url = `${process.env.NEXT_PUBLIC_API_URL}/auth/${account.provider}/callback?access_token=${account?.accessToken}`
|
||||
|
||||
if (account.provider === 'twitter') {
|
||||
url = `${process.env.NEXT_PUBLIC_API_URL}/auth/${account.provider}/callback?access_token=${account?.oauth_token}&access_secret=${account?.oauth_token_secret}`
|
||||
}
|
||||
|
||||
const response = await fetch(url)
|
||||
|
||||
const data = await response.json()
|
||||
token.id = data.id || user.id
|
||||
token.jwt = data.jwt || user.jwt
|
||||
|
||||
Reference in New Issue
Block a user