Skip to content

Commit

Permalink
check if accounts present
Browse files Browse the repository at this point in the history
  • Loading branch information
devksingh4 committed Jul 20, 2024
1 parent f90d88d commit 9672df9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions clientv2/src/components/AuthContext/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,13 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
throw new Error('Unknown authentication method.');
}, [userData, instance, getKindeToken]);

const loginMsal = useCallback(() => {
instance.loginRedirect();
const loginMsal = useCallback(async () => {
const accounts = instance.getAllAccounts();
if (accounts.length > 0) {
instance.setActiveAccount(accounts[0]);
} else {
await instance.loginRedirect();
}
}, [instance]);

const logout = useCallback(async () => {
Expand Down

0 comments on commit 9672df9

Please sign in to comment.