Comments (15)
@oskar-gmerek Thank you for creating the issue. Please let me know the following so that I can help you:
- Is your Strapi server up and running?
- Can you visit http://localhost:1337/admin and log into the Admin Panel of Strapi?
How NextAuth works with Strapi
- NextAuth is responsible for signing the user in
- If the sign in is successful, NextAuth will do an API call to fetch the token from Strapi here.
- Strapi will return a JWT token will be injected into the token as well as into the session object of NextAuth.
- 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.
from nextjs-strapi-boilerplate.
@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
from nextjs-strapi-boilerplate.
@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 theauthorization: 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(?)
from nextjs-strapi-boilerplate.
@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.
from nextjs-strapi-boilerplate.
- Yes, strapi server is up and running
- Yes, I can login to admin dashboard without any problems
About how it works together:
- So if I understand good. Is possible to use only frontend from the boilerplate and other backend instance? (I mean, there is no changes at the backend?) I asking because I want to use mongodb instead of postgres, and instance of strapi that already exists.
from nextjs-strapi-boilerplate.
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:
[next-auth][error][adapter_connection_error] error: role "strapi" does not exist
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:
NEXT_PUBLIC_DATABASE_URL=postgres://strapi:strapi@localhost:5432/strapi
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:
- Set up my DB env vars for strapi backend under backend/app/.env
cd backend/app && yarn install && yarn develop
(Before running this make sure your local DB server is up and running, and you have your DB created as pointed in .env...)
Now once that solved, I was still having "Try signing with a different account" but with a different error log now :
(logs from nextjs and strapi on the bottom)
[next-auth][debug][typeorm_get_user_by_provider_account_id] [ 'google', 'XXXXXXXXXX' ] <-- My OAuthProfile.id here
[next-auth][error][get_user_by_provider_account_id_error] QueryFailedError: relation "accounts" does not exist
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.
from nextjs-strapi-boilerplate.
@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.
from nextjs-strapi-boilerplate.
@oskar-gmerek Did you append ?synchronize=true
to your NEXT_PUBLIC_DATABASE_URL
like this?
I've merged #6.
from nextjs-strapi-boilerplate.
@ghoshnirmalya Yes.
from nextjs-strapi-boilerplate.
@oskar-gmerek Will it be possible for you to upload your code to a repository?
from nextjs-strapi-boilerplate.
@ghoshnirmalya
That will be not help at all in my opinion.
But here we go: https://github.com/oskar-gmerek/next-strapi-boilerplate
from nextjs-strapi-boilerplate.
@sebacampos
Strange. I was add console.log('token: ', token); after that line. Saved, after reset it started work correctly. I can login now and see the feeds. After remove that line still working, so I have no idea what happened here.
I will try again from the scratch
from nextjs-strapi-boilerplate.
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
from nextjs-strapi-boilerplate.
@sebacampos Thank you for your help.
@oskar-gmerek I'm glad that it's working fine for you.
from nextjs-strapi-boilerplate.
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:
database : {
type: 'postgres',
host: process.env.NEXT_PUBLIC_DB_HOST,
port: process.env.NEXT_PUBLIC_DB_PORT,
username: process.env.NEXT_PUBLIC_DB_USER,
password: process.env.NEXT_PUBLIC_DB_PASS,
database: process.env.NEXT_PUBLIC_DB_NAME
// synchronize: true
},
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.
from nextjs-strapi-boilerplate.
Related Issues (11)
- [Bug] Auth doesn't work for demo HOT 2
- Error when logging in by Google on the frontend HOT 2
- Google Auth - Error 400: redirect_uri_mismatch HOT 4
- "Error: Forbidden" when accessing protected pages with Google provider HOT 3
- Strapi internal email-password login method HOT 4
- How to return full User object after logging in?
- TSLint has been deprecated in favor of ESLint.
- Update starter to Strapi V4 HOT 3
- message: "Cannot read property 'id' of undefined", :( HOT 1
- I don't understand NEXT_PUBLIC_DATABASE_URL
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nextjs-strapi-boilerplate.