-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Postgres connection problems after fresh repository cloned #4
Comments
@oskar-gmerek Thank you for creating the issue. Please let me know the following so that I can help you:
How NextAuth works with Strapi
I hope that this helps. Let me know if you need further clarification. |
About how it works together:
|
Hi @oskar-gmerek I was having the same problem and just solved like this: If you look closely, you will find this on your console:
That means, no user "strapi" found for DB conection. So in order to solve it, make sure that your env variables matches your DB settings:
If you are running on Docker, just make sure that you can connect to the DB with the NEXT_PUBLIC_DATABASE_URL. I personally ended up running the strapi backend locally instead of using Docker. So I set up my local Postgres Server instead of dockerizing it (just for convinience because I already had some other strapi projects in which I use local Postgress Server) ... That means:
Now once that solved, I was still having "Try signing with a different account" but with a different error log now :
Haven't used NextAuth in any other projects, but basically, TypeORM (NextAuth default DB adapter) couldn't find the 'Accounts' Table in DB... After having a look on NextAuth Documentation I realized that some further config was needed to setup DB. If you are running postgres here you'll find the schema you need: https://next-auth.js.org/schemas/postgres After updating the schema, I could make it work but still with some tweaks not DB problems so will leave them for another issue maybe. e.g Now I'm dealing with an error on session management but still trying to understand why it is happening: [next-auth][error][jwt_session_error] TypeError: payload must be an object. For more info on the errors have a look on this Error page on NextAuth documentation which I just found from doing a search on the documentation, because apparently it is not available from the navigation menu 🤷♂️ @ghoshnirmalya maybe it would be nice to add some more clarification on this DB settings on the documentation part. Hope this helps anyone having trouble with the DB Connection. |
@sebacampos Thank you for your help. Really appreciate it. @oskar-gmerek I've created a Pull Request to update the documentation which should fix your issue. Please let me know if you're still facing this issue after following the steps in the readme.md file. |
@ghoshnirmalya Unfortunately, the same error was popping up. Using the @sebacampos hint, I changed the port for postgres into docker-compose and .env Another error has occurred. Here @sebacampos comes in handy again with his PR #6 , after removing '/graphql' from NEXT_PUBLIC_API_URL in .env |
@oskar-gmerek Did you append I've merged #6. |
@ghoshnirmalya Yes. |
@oskar-gmerek Will it be possible for you to upload your code to a repository? |
@ghoshnirmalya But here we go: https://github.com/oskar-gmerek/next-strapi-boilerplate |
@oskar-gmerek any console log when you get that error? Since the error is "Error: Invalid token" I would suggest:
|
@sebacampos I will try again from the scratch |
Often happens 😄. It must have been that NEXT_PUBLIC_DATABASE_URL change that didn't take effect until the server was reset or smth like that |
@ghoshnirmalya @sebacampos Thanks for help. Thats look like working fine now. I have cloned last version again, follow all steps and is working so I close the issue as it no longer an issue. Thanks one more time. |
@sebacampos Thank you for your help. |
I have same error but found out the reason turned out to be incorrect postgres connection string (the password has special @ character and even though I have escaped it with %40 it is still not working - while the URI works well with psql command). After many other attempts and document reference (https://next-auth.js.org/configuration/databases) I have decided to change the configuration to json values like below and it works well:
Of course this means I have to add corresponding variables in env.local. I think digging deeper into the pg library could give the actual reason but since I am so eager to explore nextjs + strapi combination I would accept this solution by now. Hope this helps. |
Hello, first of all, thank you that you have decided to fill in this lack of a suitable tool for combining strapi authentication with next-auth authorization.
I have such a problem. Freshly cloned from GitHub, my google auth data in .env and when I try to create an account or sign in then I got the error: "Try signing with a different account." (logs from nextjs on the bottom)
Google?NextJS? can't connect to database, but I don't know why? I didn't chance anything...
in env:
NEXT_PUBLIC_DATABASE_URL=postgres://strapi:strapi@localhost:5432/strapi
by the way... Can you explain how this is working? Does next-auth connect directly to the database? Completely disregarding the Strapi? It should working identical without Strapi?
`event - build page: /api/auth/[...nextauth]
wait - compiling...
event - compiled successfully
[next-auth][debug][profile_data] {
id: 'xxx',
email: 'xxx@gmail.com',
verified_email: true,
name: 'xxx',
given_name: 'xxx',
family_name: 'xxx',
picture: 'https://xxx.x/photo.jpg',
locale: 'xx'
}
[next-auth][debug][oauth_callback_response] {
profile: {
name: 'xxx',
email: 'xxx@gmail.com',
image: 'https://xxxx.x/photo.jpg'
},
account: {
provider: 'google',
type: 'oauth',
id: 'xxx',
refreshToken: undefined,
accessToken: 'xxx.xxxx.xxx',
accessTokenExpires: null
},
OAuthProfile: {
id: 'xxxx',
email: 'xxx@gmail.com',
verified_email: true,
name: 'xxx',
given_name: 'xxx',
family_name: 'xxx',
picture: 'https://xxx.x/photo.jpg',
locale: 'xx'
}
}
[next-auth][error][adapter_connection_error] error: role "strapi" does not exist
at Parser.parseErrorMessage (/Users/xxxx/test-env/nextjs-strapi-boilerplate/frontend/node_modules/pg-protocol/dist/parser.js:278:15)
at Parser.handlePacket (/Users/xxx/test-env/nextjs-strapi-boilerplate/frontend/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/Users/xxx/test-env/nextjs-strapi-boilerplate/frontend/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket. (/Users/xxx/test-env/nextjs-strapi-boilerplate/frontend/node_modules/pg-protocol/dist/index.js:8:42)
at Socket.emit (events.js:314:20)
at addChunk (_stream_readable.js:303:12)
at readableAddChunk (_stream_readable.js:279:9)
at Socket.Readable.push (_stream_readable.js:218:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
length: 98,
severity: 'FATAL',
code: '28000',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'miscinit.c',
line: '607',
routine: 'InitializeSessionUserId'
}
https://next-auth.js.org/errors#adapter_connection_error
[next-auth][error][oauth_callback_handler_error] TypeError: Cannot destructure property 'manager' of 'connection' as it is null.
at Object. (/Users/xxx/test-env/nextjs-strapi-boilerplate/frontend/node_modules/next-auth/dist/adapters/typeorm/index.js:102:9)
at Generator.next ()
at asyncGeneratorStep (/Users/xxxx/test-env/nextjs-strapi-boilerplate/frontend/node_modules/next-auth/dist/adapters/typeorm/index.js:28:103)
at _next (/Users/xxxx/test-env/nextjs-strapi-boilerplate/frontend/node_modules/next-auth/dist/adapters/typeorm/index.js:30:194)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
https://next-auth.js.org/errors#oauth_callback_handler_error`
The text was updated successfully, but these errors were encountered: