Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Feb 5, 2025
2 parents a66daa0 + 9f9bd37 commit 137be2e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/core/src/services/auth.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {SignInError} from '../types/errors.types';
import {createAuthClient} from '../utils/auth.utils';
import {initUser} from './user.services';

let authClient: AuthClient | undefined;
// eslint-disable-next-line local-rules/use-option-type-wrapper
let authClient: AuthClient | undefined | null;

export const initAuth = async (provider?: Provider) => {
authClient = authClient ?? (await createAuthClient());
Expand Down Expand Up @@ -73,12 +74,18 @@ export const signOut = async (): Promise<void> => {
await authClient?.logout();

// Reset local object otherwise next sign in (sign in - sign out - sign in) might not work out - i.e. agent-js might not recreate the delegation or identity if not resetted
authClient = undefined;
// Technically we do not need this since we recreate the agent below. We just keep it to make the reset explicit.
authClient = null;

AuthStore.getInstance().reset();

ActorStore.getInstance().reset();
AgentStore.getInstance().reset();

// Recreate an HttpClient immediately because next sign-in, if window is not reloaded, would fail if the agent is created within the process.
// For example, Safari blocks the Internet Identity (II) window if the agent is created during the interaction.
// Agent-js must be created either globally or at least before performing a sign-in.
authClient = await createAuthClient();
};

export const getIdentity = (): Identity | undefined => authClient?.getIdentity();
Expand Down

0 comments on commit 137be2e

Please sign in to comment.