-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c91f90c
commit d75bfbe
Showing
7 changed files
with
87 additions
and
47 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,40 @@ | ||
import NextAuth from 'next-auth/next' | ||
import GoogleProvider from 'next-auth/providers/google' | ||
import NextAuth from 'next-auth'; | ||
import connectDb from '../../../middleware/mongoose'; | ||
import GoogleProvider from 'next-auth/providers/google'; | ||
import User from '../../../models/User'; | ||
|
||
export default NextAuth({ | ||
providers: [ | ||
GoogleProvider({ | ||
clientId: process.env.GOOGLE_CLIENT_ID, | ||
clientSecret: process.env.GOOGLE_CLIENT_SECRET | ||
clientSecret: process.env.GOOGLE_CLIENT_SECRET, | ||
}), | ||
], | ||
secret: process.env.JWT_SECRET | ||
secret: process.env.JWT_SECRET, | ||
callbacks: { | ||
async jwt({ token, account, profile }) { | ||
await connectDb(); | ||
|
||
if (account && profile) { | ||
let existingUser = await User.findOne({ email: profile.email }); | ||
|
||
if (!existingUser) { | ||
existingUser = new User({ | ||
name: profile.name, | ||
email: profile.email, | ||
}); | ||
await existingUser.save(); | ||
} | ||
|
||
token.userId = existingUser._id; | ||
} | ||
|
||
return token; | ||
}, | ||
async session({ session, token }) { | ||
session.userId = token.userId; | ||
return session; | ||
}, | ||
}, | ||
|
||
}); |
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
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
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