Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Error handling skipped on init) CompleteAuth not triggered for init #161

Open
parlir opened this issue Jan 17, 2023 · 1 comment
Open

Comments

@parlir
Copy link

parlir commented Jan 17, 2023

When using the init flow it will skip over completeauth when errors occur and therefore error handling is skipped.

scenario is as follows:

  1. User triggers init in code
  2. authorize function sets SessionStorage with state_key here https://github.com/parlir/client-js/blob/master/src/smart.ts#L270
    and here https://github.com/parlir/client-js/blob/master/src/smart.ts#L303
  3. Redirect happens (and user authorizes and is redirected back to where init was called)
  4. Init called again post redirect and only checks for code and state (as opposed to other parameters such as error etc...
    https://github.com/parlir/client-js/blob/master/src/smart.ts#L758
  5. State has been set on previous calls and so cache is set and init returns client swallowing the error in the process here
    https://github.com/parlir/client-js/blob/master/src/smart.ts#L768

I think a quick fix to this issue could be to check for error parameter and call the completeauth function if error parameter exists on step 4.

@vlad-ignatov I'm happy to open a PR for this let me know wyt.

@parlir
Copy link
Author

parlir commented Jan 17, 2023

Can confirm the following modifications on init function worked for me:

    const error = url.searchParams.get("error");

    // if error or (`code` and `state`) params are present we need to complete the auth flow
    if (error || code && state) {
        return completeAuth(env);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant