Closed a0m0rajab closed 2 weeks ago
As mentioned in the official docs, I think your problem is that your AUTH_SECRET
environment variable is empty. Use the npx auth secret
command to generate one and things should work smoothly for you
The variable is not empty.
Is it possible to check whether the environment variables are accessible correctly by the code? A simple console.log
in auth.js
should be enough
Thanks for the suggestion; I went through that path, but the env variable was not accessible since I needed to define it in the next.config
file.
I solved the issue by looking at the following links:
As for the second problem, looking into the previous discussion. I read that the functions i tried to use are server-side functions and needed to use the client side ones: https://github.com/nextauthjs/next-auth/issues/9192#issuecomment-1821319670
After doing that, I needed to change the baseURL of the session provider to make it work with my project since we had i18n configurations.
I think keeping this open for the maintainers to notice the issue would be helpful. I opened an issue for documentation improvements as well: https://github.com/nextauthjs/next-auth/issues/10720
@khobiziilyes thank you for the help!
Using await auth()
in client component is not yet supported.
I followed the docs here:
https://authjs.dev/getting-started/session-management/get-session
I ended up using SessionProvider
instead.
Error: async/await is not yet supported in Client Components, only Server Components. This error is often caused by accidentally adding
'use client'
to a module that was originally written for the server.
next 14.2.3 next-auth 5.0.0-beta.17
@borzaka can you provide an example of the provider that you had? for me I did use the examples from v4 to run that.
@a0m0rajab I used the official example repo: https://github.com/nextauthjs/next-auth-example/tree/main You can test it here: https://next-auth-example.vercel.app/client-example
auth()
is not meant to be used client-side. The underlying issue is that your AUTH_SECRET
is empty (on the client), which is the way it shuold be.
We highly recommend you get the session server-side (with auth()
) and then pass it down to client-components via props, btu if you need to do somethign like that client-side you can still use the getSession
method from next-auth/react
and wrap your client tree in a <SessionProvider />
. For example, see our client page example: https://github.com/nextauthjs/next-auth-example/blob/main/app/client-example/page.tsx
EDIT: Looks like you already figured out a lot of this haha. I'll close the issue then :pray:
@ndom91 thanks for the information, yeah it was not clear from the first sight in the docs. took some time haha. But thanks again for letting me know how things works here.
Here is another old issue with the same concept though: https://github.com/nextauthjs/next-auth/issues/7981
Environment
Reproduction URL
https://github.com/ayasofyazilim-clomerce/ayasofyazilim-core-project/pull/67
Describe the issue
Implementing authjs with credentials provider in my app created the next issue when i used beta.16, I was expecting to use the auth() function immediately and work with it:
Even though I had the secret provided in my .env file it did not detect it.
.env file: has the next variables (I removed them for security reasons)
trial 1:
When I tried to downgrade the version of the library I got a different error:
Error: Invariant: headers() expects to have requestAsyncStorage, none available. #9192
How to reproduce
Expected behavior
I am expecting the auth() function to work on client side.