Skip to content

Commit

Permalink
Merge pull request #128 from asgardeo/fix-multiple-render-strict-mode
Browse files Browse the repository at this point in the history
Fix multiple rendering of the signIn flow
  • Loading branch information
yathindrak committed Aug 22, 2022
2 parents 03fae63 + bb47b3a commit e443d0d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/src/authenticate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import React, {
useContext,
useEffect,
useMemo,
useRef,
useState
} from "react";
import { AuthParams, ReactConfig } from ".";
Expand Down Expand Up @@ -77,6 +78,8 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
(): AuthReactConfig => ({ ...defaultConfig, ...passedConfig }), [ passedConfig ]
);

const isSignInInitiated = useRef(false);

const signIn = async(
config?: SignInConfig,
authorizationCode?: string,
Expand Down Expand Up @@ -146,6 +149,13 @@ const AuthProvider: FunctionComponent<PropsWithChildren<AuthProviderPropsInterfa
* Try signing in when the component is mounted.
*/
useEffect(() => {
// Prevent multiple renderings
if (isSignInInitiated.current) {
return;
}

isSignInInitiated.current = true;

(async () => {
let isSignedOut: boolean = false;
// If the component was mounted after the user was redirected to the application upon a successful logout,
Expand Down

0 comments on commit e443d0d

Please sign in to comment.