Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/ts-api-react/src/SessionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export interface ContextInterface {
/** Store given CurrentUser */
storeCurrentUser: (currentUser: User) => void;
/** Function to get the currentUser */
getSessionCurrentUser: () => Promise<User | EmptyUser>;
getSessionCurrentUser: (
forceUpdateCurrentUser?: boolean
) => Promise<User | EmptyUser>;
}

interface SessionData {
Expand Down Expand Up @@ -204,10 +206,10 @@ const emptyCurrentUser: EmptyUser = {
};

export const getSessionCurrentUser = async (
_storage: StorageManager
_storage: StorageManager,
forceUpdateCurrentUser: boolean = false
): Promise<User | EmptyUser> => {
const isStale = _storage.safeGetValue(STALE_KEY);
if (!(typeof isStale === "string") || !(isStale === "no")) {
if (forceUpdateCurrentUser || _storage.safeGetValue(STALE_KEY) === "yes") {
// If the session is stale, we need to refresh it
await updateCurrentUser(_storage);
}
Expand Down Expand Up @@ -262,8 +264,8 @@ export const getSessionContext = (
updateCurrentUser(_storage);
};

const _getSessionCurrentUser = () => {
return getSessionCurrentUser(_storage);
const _getSessionCurrentUser = (forceUpdateCurrentUser: boolean = false) => {
return getSessionCurrentUser(_storage, forceUpdateCurrentUser);
};

if (typeof window !== "undefined") {
Expand Down
Loading