-
-
Save Nilanth/89802fca95dee783c1d53b1536e3716f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import NextAuth from "next-auth" | |
import TwitterProvider from "next-auth/providers/twitter" | |
import {cloneDeep} from "tailwindcss/lib/util/cloneDeep"; | |
export default NextAuth({ | |
// Configure one or more authentication providers | |
providers: [ | |
TwitterProvider({ | |
clientId: process.env.TWITTER_ID, | |
clientSecret: process.env.TWITTER_SECRET | |
}), | |
// ...add more providers here | |
], | |
callbacks: { | |
async jwt({token, user, account, profile, isNewUser}) { | |
if (profile) { | |
token['userProfile'] = { | |
followersCount: profile.followers_count, | |
twitterHandle: profile.screen_name, | |
userID: profile.id | |
}; | |
} | |
if (account) { | |
token['credentials'] = { | |
authToken: account.oauth_token, | |
authSecret: account.oauth_token_secret, | |
} | |
} | |
return token | |
}, | |
async session({session, token, user}) { | |
// Send properties to the client, like an access_token from a provider. | |
let userData = cloneDeep(token.userProfile); | |
delete userData.userID; | |
session.twitter = userData; | |
return session; | |
} | |
}, | |
secret: process.env.NEXTAUTH_SECRET, | |
pages: { | |
error: '/error', // Error code passed in query string as ?error= | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment