Closed Kingside88 closed 1 year ago
It happens the same to me. logout just refreshes the page
I provide a full keycloak demo and nuxt 3 starter pack from sfx-code.
you can use it for testing purposes.
Just clone it, add .env file provided from markdown and pnpm run dev
will start your're demo instance
https://github.com/Kingside88/nuxt3-primevue-starter-auth
Hey @Kingside88 👋
Thank you for the very generous reproduction - it's amazing that you setup and made a vailable a full keycloak instance for this!
I just tested it through: I cannot reproduce the error: When I click "sign out" I see the signout request happening + am redirected to the login page. Refreshing or manually trying to navigate to /
also forces me back onto the login page.
Here's the sequence of commands I ran:
> git clone https://github.com/Kingside88/nuxt3-primevue-starter-auth
> cd nuxt3-primevue-starter-auth
# ... create .env file
> pnpm i
> pnpm run dev
I also tried it via pnpm run build && pnpm run preview
and could nstill not see the behavior. What am I missing?
Btw: could you update the repro to use @sidebase/nuxt-auth@0.4.0-alpha.6
which we just released?
I also just tried to replicate this with a github-oauth provider + firefox -> I was logged out as expected on the latest version.
thank you for taking time for my issue. I updated the package.
But now defaultProvider: 'keycloak'
seems to be ignored.
I expect the login page without selecting "Sign in with keycloak"
When you close the session in the application in keycloak it is still active and when you re-enter the application it does not ask you again for the credentials. What is the programmed behavior?. SignIn always ask for credentials SignOut always clean session data and close the session on keycloak, this is the desired behavior, how can we achieve this?
[next-auth][error][OAUTH_CALLBACK_ERROR] 18:48:17 https://next-auth.js.org/errors#oauth_callback_error checks.state argument is missing { error: TypeError: checks.state argument is missing ....providerId: 'keycloak', message: 'checks.state argument is missing' }
When you close the session in the application in keycloak it is still active and when you re-enter the application it does not ask you again for the credentials. What is the programmed behavior?. SignIn always ask for credentials SignOut always clean session data and close the session on keycloak, this is the desired behavior, how can we achieve this?
We could use the keycloak REST Api. The keycloak provider do the same.
https://www.keycloak.org/docs-api/18.0/rest-api/#_users_resource
you can search for Remove all user sessions associated with the user Also send notification to all clients that have an admin URL to invalidate the sessions for the particular user.
I dont know if this is related or should I open a different issue, since the original problem was the redirection when login out but turned to be into something else.
Anyway, regarding the original issue of refreshing the page. Looks like after upgrading Nuxt Auth from ^0.3.3 to ^0.4.0. signOut({callbackUrl: "/foo"}) No longers works as expected and this causes a full refresh on the page.
According to Auth Next documentation the recommendation is to use it as: signOut({redirect: false, callbackUrl: "/foo"})
However, in Nuxt this doesn't work. It doesn't refresh anymore but it does not redirect to the callbackUrl as before.
Let me know if there is something I can do to further test this problem or if there is already any workaround.
thanks
Thanks to this tutorial https://blog.devgenius.io/security-in-vuejs-3-0-with-authentication-and-authorization-by-keycloak-part-1-ae884889fa0d
I created a vanilla vue 3 project including pure keycloakJs package. It works like a charm from minute 1. I created a demo vue 3 app linked to my demo keycloak instance. In my case I will implement it in nuxt 3 and use it there. https://github.com/Kingside88/vue3-auth-keycloakJs
I like the idea of just using a provider but it seems to me the dependencies are to heavy. nuxt-auth is dependend on next-auth and both are dependend on provider written by nobody knows.
Using official libraries is better than be depended on 3rd parties. I will update you guys if my solution is ready so everybody can use it
Ok guys, I've got an update for you. Nuxt 3 is running with official keycloakJs Javascript package. You can get a ready to go demo here: https://github.com/Kingside88/nuxt3-primevue-starter-auth/blob/keycloakJs/README.md The sidebase/nuxt-auth or better say next-auth keycloak provider has a bug providing the JWT token. It misses some properties. Now we can compare both solutions.
As there has not been any progress here for a while I will close this issue. It seems like the issue has more to do with NextAuth. Maybe a good next step would be to contact them and investigate futhur!
Environment
Nuxt project info: 08:10:52
Windows_NT
v18.13.0
3.0.0
2.1.1
npm@8.19.3
vite
ssr
,runtimeConfig
,auth
,modules
,content
,experimental
,vueuse
,unocss
,colorMode
,css
,build
@vueuse/nuxt@9.10.0
,@unocss/nuxt@0.48.4
,@pinia/nuxt@0.4.6
,@nuxtjs/color-mode@3.2.0
,@formkit/nuxt@1.0.0-beta.12
,@nuxt/content@2.3.0
,@sidebase/nuxt-auth@0.4.0-alpha.5
Build Modules:
-
Reproduction
Hi, according to this feature: https://github.com/sidebase/nuxt-auth/issues/154
Unfortunately I can no longer SignOut if "defaultProvider" is set. SignOut redirect back to my page and do not SignOut.
Using newest version "0.4.0-alpha.5" nuxt.config.ts auth: { enableGlobalAppMiddleware: true, defaultProvider: 'keycloak' }, server\api\auth[...].ts `import KeycloakProvider from 'next-auth/providers/keycloak' import { NuxtAuthHandler } from '#auth'
export default NuxtAuthHandler({ debug: true, secret: process.env.AUTH_SECRET,
providers: [ // @ts-expect-error You need to use .default here for it to work during SSR. May be fixed via Vite at some point KeycloakProvider.default({ clientId: process.env.AUTH_CLIENT_ID ?? "", clientSecret: process.env.AUTH_SECRET, issuer: process.env.AUTH_ISSUER ?? "", idToken: true, wellKnown: process.env.AUTH_WELLKNOWN ?? "", }), ], callbacks: { session: (data : any) => { return data.session }, }, }) `
Describe the bug
After signOut() the page refresh and the user ist still logged in
Additional context
No response
Logs