Created
October 4, 2021 11:40
-
-
Save ziedHamdi/5602f9ce9c7e213d18e9845e29a2c1cb to your computer and use it in GitHub Desktop.
pages/api/auth/[...nextauth].js
This file contains hidden or 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 Providers from 'next-auth/providers' | |
| import jwt from 'jsonwebtoken' | |
| import {TOKEN_SECRET} from "../../../lib/auth"; | |
| import logger from "../../../lib/logger"; | |
| export default NextAuth({ | |
| // Configure one or more authentication providers | |
| providers: [ | |
| Providers.Facebook({ | |
| clientId: process.env.FACEBOOK_ID, | |
| clientSecret: process.env.FACEBOOK_SECRET | |
| }), | |
| Providers.Google({ | |
| clientId: process.env.GOOGLE_ID, | |
| clientSecret: process.env.GOOGLE_SECRET | |
| }), | |
| // ...add more providers here | |
| ], | |
| // A database is optional, but required to persist accounts in a database | |
| database: process.env.DATABASE_URL, | |
| callbacks: { | |
| /** | |
| * @param {object} session Session object | |
| * @param {object} token User object (if using database sessions) | |
| * JSON Web Token (if not using database sessions) | |
| * @return {object} Session that will be returned to the client | |
| */ | |
| async session(session, token) { | |
| // logger.debug("connected user token: ", token) | |
| session.accessToken = token.accessToken | |
| session.user.id = token.id | |
| session.infraToken = jwt.sign({data:{_id:token.id, name:token.name, email:token.email}}, TOKEN_SECRET) | |
| return session | |
| } | |
| } | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment