forked from adrianhajdin/project_next_14_ai_prompt_sharing
-
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
29d79a7
commit 9a4c2b3
Showing
5 changed files
with
756 additions
and
1,740 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
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,47 +1,47 @@ | ||
import NextAuth from 'next-auth'; | ||
import GoogleProvider from 'next-auth/providers/google'; | ||
import NextAuth from "next-auth"; | ||
import GoogleProvider from "next-auth/providers/google"; | ||
|
||
import User from '@models/user'; | ||
import { connectToDB } from '@utils/database'; | ||
import User from "@models/user"; | ||
import { connectToDB } from "@utils/database"; | ||
|
||
const handler = NextAuth({ | ||
providers: [ | ||
GoogleProvider({ | ||
clientId: process.env.GOOGLE_ID, | ||
clientSecret: process.env.GOOGLE_CLIENT_SECRET, | ||
}) | ||
], | ||
callbacks: { | ||
async session({ session }) { | ||
// store the user id from MongoDB to session | ||
const sessionUser = await User.findOne({ email: session.user.email }); | ||
session.user.id = sessionUser._id.toString(); | ||
providers: [ | ||
GoogleProvider({ | ||
clientId: process.env.GOOGLE_ID, | ||
clientSecret: process.env.GOOGLE_CLIENT_SECRET, | ||
}), | ||
], | ||
callbacks: { | ||
async session({ session }) { | ||
// store the user id from MongoDB to session | ||
const sessionUser = await User.findOne({ email: session.user.email }); | ||
session.user.id = sessionUser._id.toString(); | ||
|
||
return session; | ||
}, | ||
async signIn({ account, profile, user, credentials }) { | ||
try { | ||
await connectToDB(); | ||
return session; | ||
}, | ||
async signIn({ account, profile, user, credentials }) { | ||
try { | ||
await connectToDB(); | ||
|
||
// check if user already exists | ||
const userExists = await User.findOne({ email: profile.email }); | ||
// check if user already exists | ||
const userExists = await User.findOne({ email: profile.email }); | ||
|
||
// if not, create a new document and save user in MongoDB | ||
if (!userExists) { | ||
await User.create({ | ||
email: profile.email, | ||
username: profile.name.replace(" ", "").toLowerCase(), | ||
image: profile.picture, | ||
}); | ||
} | ||
// if not, create a new document and save user in MongoDB | ||
if (!userExists) { | ||
await User.create({ | ||
email: profile.email, | ||
username: profile.name.replace(" ", "").toLowerCase(), | ||
image: profile.picture, | ||
}); | ||
} | ||
|
||
return true | ||
} catch (error) { | ||
console.log("Error checking if user exists: ", error.message); | ||
return false | ||
} | ||
}, | ||
} | ||
}) | ||
return true; | ||
} catch (error) { | ||
console.log("Error checking if user exists: ", error.message); | ||
return false; | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
export { handler as GET, handler as POST } | ||
export { handler as GET, handler as POST }; |
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,19 +1,19 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
experimental: { | ||
appDir: true, | ||
serverComponentsExternalPackages: ["mongoose"], | ||
}, | ||
images: { | ||
domains: ['lh3.googleusercontent.com'], | ||
}, | ||
webpack(config) { | ||
config.experiments = { | ||
...config.experiments, | ||
topLevelAwait: true, | ||
} | ||
return config | ||
} | ||
} | ||
experimental: { | ||
appDir: true, | ||
serverComponentsExternalPackages: ["mongoose"], | ||
}, | ||
images: { | ||
domains: ["lh3.googleusercontent.com"], | ||
}, | ||
webpack(config) { | ||
config.experiments = { | ||
...config.experiments, | ||
topLevelAwait: true, | ||
}; | ||
return config; | ||
}, | ||
}; | ||
|
||
module.exports = nextConfig | ||
module.exports = nextConfig; |
Oops, something went wrong.