Closed std4453 closed 7 months ago
I am having the same issue as you. I did notice in your code you didn't have SessionProvider context though. Not sure if you missed that in the example only.
Otherwise have you found a solution.
Same issue here. Have you found any workaroud?
Same issue here. Have you found any workaroud?
I'm still trying to figure out the issue with limited time. Yet to try previous next Auth version.
Does appear this has been an issue in the past too.
To clarify I am using App directory and middleware. I think it works without the middleware from memory.
@tmackness I think this all happened on server-side, the route simply redirects with 307 to signin page without any client-side js being executed, and <SessionProvider>
is on the client side, so it shouldn't matter here.
Isn't that a documented limitation? From https://next-auth.js.org/configuration/nextjs#caveats:
Only supports the "jwt" session strategy. We need to wait until databases at the Edge become mature enough to ensure a fast experience. (If you know of an Edge-compatible database, we would like if you proposed a new Adapter)
I have the same issue with using DynamoDB
adapter. Next auth middleware is always redirect to sign in page with session: 'database'
strategy.
damn its been driving me crazy.... just went and look at the middleware code, it just support jwt
.... that's really unfortunate, so I wonder how people uses it than? what's the workaround?
damn its been driving me crazy.... just went and look at the middleware code, it just support
jwt
.... that's really unfortunate, so I wonder how people uses it than? what's the workaround?
There is no workaround. The middleware only supports jwt sessions. I added this prerequisite to the docs with https://github.com/nextauthjs/next-auth/pull/10667.
The reason that caveat was added back in the old docs is no longer accurate - many database adapters are "edge compatible", meaning you can use the database adapters / database sessions with middleware now.
See:
That of course doesn't mean all database adapters will work, you have to double check that your database runs in an edge runtime, aka not using node.js.
I'm going to close this issue as we've seemingly figured out the main issue and there is newer info available ^^
@ndom91 , sorry to ask it here, where would you augment user data session, since we dont have a token which hold additional information. is this pattern ok ?
session: async ({ session, user }) => {
const result = await db.query.users.findFirst({
columns: { firstName: true, lastName: true },
where: (users, { eq }) => eq(users.id, user.id),
});
session.user.id = user.id;
session.user.firstName = result?.firstName;
session.user.lastName = result?.lastName;
return session;
},
},```
Environment
System: OS: Linux 6.4 Arch Linux CPU: (16) x64 12th Gen Intel(R) Core(TM) i5-12600KF Memory: 6.50 GB / 62.66 GB Container: Yes Shell: 3.6.1 - /usr/bin/fish Binaries: Node: 16.17.1 - ~/.local/share/nvm/v16.17.1/bin/node Yarn: 1.22.19 - ~/.local/share/nvm/v16.17.1/bin/yarn npm: 8.15.0 - ~/.local/share/nvm/v16.17.1/bin/npm pnpm: 6.7.1 - ~/.local/share/nvm/v16.17.1/bin/pnpm
Reproduction URL
https://github.com/std4453/next-auth-bug/
Describe the issue
next-auth
does not work when:next.js
v13.4.12 (other versions not tested)database
as session strategyWhen entering
/
, it jumps to/api/auth/signin
, you login, it jumps back to/api/auth/callback/keycloak
, then to/
, then to/api/auth/signin
again.As a result, you never get to use the app.
It works when using
jwt
as session strategy.I'm not sure whether this is a duplicate of #5008 , that one claims to be fixed in Next.js
v12.2.5-canary.2
or newer, yet there has since been more feedback about it not working, and it might be worth to take another look.How to reproduce
See
README
.Expected behavior
It should redirect to the OAuth provider, then back to the app, and you should be able to use it.