nextjs-strapi-boilerplate: Postgres connection problems after fresh repository cloned

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.<anonymous> (/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.<anonymous> (/Users/xxx/test-env/nextjs-strapi-boilerplate/frontend/node_modules/next-auth/dist/adapters/typeorm/index.js:102:9) at Generator.next (<anonymous>) 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`

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 15 (5 by maintainers)

Most upvoted comments

@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.

@ghoshnirmalya I cloned the repository with the new version, followed exactly as in the directions and …

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 I can log in, but is still not working as expected. Im logged, but instead of content I got “Error: Invalid token” Its probably because an user isn’t created in strapi. I guess somewhere is missed ‘/graphql’ in path after fixing like that in .env for previous error

@oskar-gmerek any console log when you get that error?

Since the error is “Error: Invalid token” I would suggest:

  • add a console.log('token: ', token) just after this line , so in line 13, to understand what is happening. I’m guessing that the authorization: Bearer ${token} on line 21 is not being sent correctly
  • Verify the token on jwt.io Debugger.
  • Verify if you have any JWT_SECRET env var, which might be causing conflict on encoding/decoding the jwt maybe(?)

@ghoshnirmalya I cloned the repository with the new version, followed exactly as in the directions and …

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 I can log in, but is still not working as expected. Im logged, but instead of content I got “Error: Invalid token” Its probably because an user isn’t created in strapi. I guess somewhere is missed ‘/graphql’ in path after fixing like that in .env for previous error

@oskar-gmerek Thank you for creating the issue. Please let me know the following so that I can help you:

  1. Is your Strapi server up and running?
  2. Can you visit http://localhost:1337/admin and log into the Admin Panel of Strapi?

How NextAuth works with Strapi

  1. NextAuth is responsible for signing the user in
  2. If the sign in is successful, NextAuth will do an API call to fetch the token from Strapi here.
  3. Strapi will return a JWT token will be injected into the token as well as into the session object of NextAuth.
  4. Every time, a request is made to Strapi from the Front-end Next.js application, the token will be passed in the header.

I hope that this helps. Let me know if you need further clarification.