uuid#parse TypeScript Examples

The following examples show how to use uuid#parse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SocailLoginsSuccess.tsx    From frontegg-react with MIT License 4 votes vote down vote up
SocialLoginsSuccess: FC = () => {
  const routes = useAuthRoutes();
  const onRedirectTo = useOnRedirectTo();
  const socialLoginState = useSocialLoginState();
  const { resetSocialLoginsState, setSocialLoginError, loginViaSocialLogin } = useSocialLoginActions();
  const location = useLocation();
  const { t } = useT();
  const redirectUri = useRedirectUri();
  const { replace: historyReplace } = useHistory();

  useEffect((): void => {
    const params: URLSearchParams = new URLSearchParams(location.search);
    const state = params.get('state');
    const code = params.get('code');
    const codeVerifier: any = localStorage.getItem(FRONTEGG_CODE_VERIFIER);
    localStorage.removeItem(FRONTEGG_CODE_VERIFIER);

    let parsedState: ISocialLoginCallbackState;
    const error = t('auth.social-logins.error.invalid-callback-url');

    if (!state || !code) {
      setSocialLoginError({ error });
      return;
    }

    try {
      parsedState = JSON.parse(state);
      if (parsedState.afterAuthRedirectUrl)
        historyReplace({ pathname: location.pathname, search: `?redirectUrl=${parsedState.afterAuthRedirectUrl}` });
    } catch (e) {
      setSocialLoginError({ error });
      return;
    }

    if (!parsedState.action || !parsedState.provider) {
      setSocialLoginError({ error });
      return;
    }

    switch (parsedState.action) {
      case SocialLoginsActions.Login:
      case SocialLoginsActions.SignUp:
        loginViaSocialLogin({
          code,
          redirectUri,
          codeVerifier,
          provider: parsedState.provider,
          metadata: JSON.stringify({
            allowMarketingMaterial: parsedState.allowMarketingMaterial,
            acceptedTermsOfService: parsedState.acceptedTermsOfService,
          }),
        });
        break;
      default:
        setSocialLoginError({ error });
    }
  }, []);

  if (socialLoginState.firstLoad || socialLoginState.loading) {
    return (
      <div className={'fe-center'}>
        <Loader />
      </div>
    );
  }

  return (
    <>
      <div className='fe-error-message'>{socialLoginState.error}</div>
      <Button
        fullWidth={true}
        onClick={() => {
          resetSocialLoginsState();
          onRedirectTo(routes.loginUrl);
        }}
      >
        {t('auth.login.back-to-login')}
      </Button>
    </>
  );
}