Technologies:
Tolerim
23 days ago
What is the process for registering a new user using GoogleProvider in NextJS 13?
In my NextJS 13 app, I am trying to incorporate Google Auth by creating a user in my database. This user will have properties such as
balance
and role
, but I am unable to find the solution. I have added the signIn
callback function to my src/app/api/auth/[...nextauth]/route.ts
file, but whenever I click the "Sign in with Google" button, an error modal is displayed by Next. The error mentions that the top-level-await experiment is not enabled. Although different solutions, such as adding a webpack
property to next.config.js
, can be found, I want to know my mistake or any possible solution to this.Answers(1)
Tolerim
23 days ago
Verified Answer
It seems that the error you're encountering is related to the top-level-await experimental feature in Node.js. This error message suggests that this experimental feature is not enabled.
To fix this, you can add the following line to your next.config.js file:
module.exports = {
experimental: {
topLevelAwait: true
}
}
This configuration will enable the top-level-await feature and should resolve the error you're encountering.
Regarding creating a user in your database when a user signs in with Google, your current implementation looks correct. The signIn callback function should be called whenever a user signs in through any provider. If the user does not exist in your database, you create a new user using the createUser function provided by your user-service module.
Make sure that you have correctly imported and implemented createUser function. Also, ensure that you have set up your database and connection properly.