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

Logging in between 2 Different Accounts Retains Stale Token Data (Only iOS, not Web) #181

Open
allidoisace opened this issue Nov 3, 2022 · 0 comments

Comments

@allidoisace
Copy link

I am not sure if I am doing something wrong, but I login to 1 account, correct data from the API shows up. I then logout and login to a different account, the previous token still seems to be valid and is used in the API request, therefore showing data from the previous logged in account.

Login from a button and subscribing to sign in success.

useEffect(() => {
    sub = Auth.Instance.events$.subscribe((action: any) => {
      if (
        action.action === AuthActions.SignInSuccess
      ) {
        history.replace(props.redirect);
      } else {
        console.error(action.action);
      }
    });

    return () => {
      sub.unsubscribe();
    };
  }, []);

  const handleSubmit = (event: any) => {
    event.preventDefault();
    try {
      Auth.Instance.signIn();
    } catch (e: any) {
      console.error(e);
    }
  };

Logout initiated from a button.

const logout = async (e: any) => {
    e.preventDefault();
    Auth.Instance.signOut();

    history.replace('/login');
  };

API Helper that puts the token into the header of an API request

export const apiRequestHandler = async (): Promise<any> => {
  const response = await Auth.Instance.getValidToken();
  console.log(response);
  const options: any = {
    headers: {},
  };
  if (response.tokenType === 'bearer') {
    options.headers.Authorization = `${response.tokenType} ${response.accessToken}`;
  }
  return options;
}
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