descope/vue-sdk

routeGuard always returning false

arvi-nagaraj opened this issue ยท 9 comments

I am trying to write a navigation guard with vue-router that checks for authenticated status and do appropriate navigations.

I am following the examples in the repo and trying to implement something exactly like this: https://github.com/descope/vue-sdk/blob/main/example/router.ts#L40.

The problem is routeGuard() resolves with false always - irrespective of the auth status.

To reproduce: https://github.com/arvi-nagaraj/descope-vue

Please help.

nirgur commented

Hello @arvi-nagaraj,

I have reviewed the example you provided, and it appears to be functioning correctly.
After logging in, I see that isAuthenticated consistently evaluates to true when navigating to different pages within the application.

I suggest giving it another attempt, ensuring that you log in before testing.
If the issue persists, kindly provide more comprehensive steps or any additional details that may help us identify the problem.

Thank you!
image

Hey @nirgur ,

yes, You are right. But this is still happening to me on certain occasions.

  1. After redirect happens from successful sso login, isAuthenticated comes as false.
  2. Whenever page is reloaded, isAuthenticated is false.
nirgur commented

Hey @arvi-nagaraj!

I double-checked everything, and it's actually working just fine.
After you move to the next route, the isAuthenticated becomes true, and even if you refresh the page, it stays that way.

If you're still having trouble, could you please share the steps to reproduce the issue?
We'd love to help figure out what's going on.

Thanks! ๐Ÿ˜Š

Hey @nirgur , I am still facing this issue. It happens after login everytime. I pushed some changes to the sample repo I provided - easier now to observe the issue. Request you to pull and take a look one more time.

If you still doesnt see the problem , maybe I am missing something out. Is there any way we can sync and figure out?

nirgur commented

If I understand correctly, you are attempting to redirect to another application path upon successful login.
To achieve this, you should listen for the success event and change the location accordingly within the callback function.

For instance, you can implement the following code:

<script setup lang="ts">
import { Descope } from "@descope/vue-sdk";

const handleError = (e: unknown): void => {
  console.error("Could not log in", e);
};

const handleSuccess = (): void => {
  window.location.href = '/#/hello'
};

// Id of the login/signup UI flow created in descope.
const flowId = "sign-in";
</script>

<template>
  <Descope :flowId="flowId" @error="handleError" @success="handleSuccess"/>
</template>

<style scoped lang="scss"></style>

You can also see additional example in our example application here

Please note that the redirectUrl property you previously used serves a different purpose.
It is intended for redirecting back from the OAuth provider or IdP, or for setting the link in the "Magic Link" and "Enchanted Link" message sent to the user.

Kindly try the updated code, and if you encounter any issues, feel free to let me know.
If needed, we can schedule a quick Zoom call to assist you further.

Hey @nirgur ,

Thanks so much for the detailed solution. I tried with the above code.
But intermittently - after login isAuthenticated becomes false.

would be happy to connect with you, please let me know a time which works for you.

nirgur commented

Hello @arvi-nagaraj,

After conducting a thorough investigation, it appears that I have identified the root cause of the issue.
To address it, I've created a Pull Request (PR) with the necessary fixes.
Before merging, I'd appreciate it if we could schedule a brief Zoom call to confirm that the proposed solution effectively resolves the problem for you.

To facilitate communication, kindly join our Slack channel using the following invite link: https://join.slack.com/t/authtown/shared_invite/zt-20fgnsb79-EpmZ~y3N2iiRUsLW~0SEIQ

Thank you!

@nirgur This link is not working for me.

But I tested your solution by checking out your branch and linking as a local package. It works and effectively resolves the problem.

Thanks so much for the help

nirgur commented

Many thanks for the update and all the cooperation!
We've just rolled out version 1.0.2 with the fix included. Cheers!