HELP - Call Login page only when button clicked - KeycloakJs and Vue3

434 views
Skip to first unread message

Eloise Ferreira

unread,
May 9, 2023, 2:17:59 PM5/9/23
to Keycloak User
Hello, I'm using the keycloak js adapter with my vue3 application. And I need to call the login page only when the user clicks the Login Button,  not when the app is mounted. I have already tried some solutions but none worked.

Here's the code I'm using to call the login


Captura de tela de 2023-05-09 15-17-21.png

Björn Pedersen

unread,
May 10, 2023, 8:05:08 AM5/10/23
to Keycloak User
I would guess  the onload: login-required triggers this, as it tells the keycloak adapater to force a login page load.

Jon Koops

unread,
May 10, 2023, 8:29:53 AM5/10/23
to Björn Pedersen, Keycloak User
Correct, the 'login-required' option will force a user to sign in if they are not already.

--
You received this message because you are subscribed to the Google Groups "Keycloak User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keycloak-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/keycloak-user/43d856ee-b9cb-44b2-9e89-2c7c3339bbf9n%40googlegroups.com.

Eloise Ferreira

unread,
May 10, 2023, 8:33:18 AM5/10/23
to Keycloak User
So, I need to have a public landing page, so the user can't be forced to login at the application start, it has to be triggered by a click > go to keycloak login page if its not logged > Redirect to application once the credentials are given. I already tried changing onLoad to check-sso, but I dont think it worked. Any ideias?

Jon Koops

unread,
May 10, 2023, 11:18:04 AM5/10/23
to Eloise Ferreira, Keycloak User
The 'check-sso' option should work if you don't want to require your users to sign in. I'd recommend reading the documentation.

Eloise Ferreira

unread,
May 18, 2023, 11:22:55 AM5/18/23
to Keycloak User
I tried to use check-sso, but the url give me this error: #error=login_required&state=c7d6d227-5b23-4b21-962a-8e6291545f55

I tried to set the checkLoginIframe to true and false, but none worked. I'm trying to redirect to a "login" page (calling a backend route to check the user type) so it can redirect again to another page based on the role. But Keycloak js dont even generate a token.

Does anyone know where I can find some material from someone with the same problem, trying to have a public landing page in the website

Jon Koops

unread,
May 18, 2023, 1:24:01 PM5/18/23
to Eloise Ferreira, Keycloak User
Did you try to use the silentCheckSsoRedirectUri option in combination with 'check-sso'? It should prevent a redirect by checking the status of the session in an iframe in the background.

Anubhav Kumawat

unread,
May 24, 2023, 7:14:59 AM5/24/23
to Jon Koops, Eloise Ferreira, Keycloak User
Hi
[Testing] Did you receive my previous messages? I don't see them in the conversation mailchain.

Anubhav Kumawat

unread,
May 24, 2023, 7:24:18 AM5/24/23
to Jon Koops, Eloise Ferreira, Keycloak User
I guess not(quite strange, tried sending them from the google mail group but it's now showing; sent from gmail and it worked).

Regardless, the solution which I mentioned in previous reply was that you can create your own Login URL
`${YOUR_KEYCLOAK.DOMAIN}/auth/realms/${YOUR_KEYCLOAK.APP_REALM}/protocol/openid-connect/auth?client_id=${YOUR_KEYCLOAK.APP_CLIENT_ID}&redirect_uri=${KEYCLOAK.REDIRECT_SIGN_IN }%2Fresponse_type=${YOUR_KEYCLOAK.RESPONSE_TYPE(You can use response type as `code` here)}&scope=openid%20profile%20openid%20offline_access&response_mode=query`;

You can redirect the user to the above url when they click on the Login button from your public landing page. So instead of your keycloak-js library doing this you can call this url by yourself. Post Login(once users enter their credentials and are redirected back to your app), you can use the react-keycloak/web library to do the further steps (like getting access token etc.)

This will help you to skip the direct Login which the keycloak-js forces you to do and help you give more control of the flow.
Do give it a try and it should work.
Reply all
Reply to author
Forward
0 new messages