Skip to content

Export last user helper functions (setLastUserLoginId, removeLastUserLoginId, etc.) #1331

Description

@meirarmon

Problem

The storeLastAuthenticatedUser feature stores the last authenticated user in localStorage, which is useful for pre-filling login forms. However, there's no way to programmatically set or clear this data from outside the SDK.

The helper functions exist internally in packages/sdks/web-js-sdk/src/enhancers/withLastLoggedInUser/helpers.ts:

  • setLastUserLoginId(loginId: string)
  • setLastUserDisplayName(displayName: string)
  • removeLastUserLoginId()
  • removeLastUserDisplayName()

But they are not exported from the package's public API.

Use Case

When a user authenticates through a separate flow (e.g., backoffice login, SSO redirect, or impersonation), the application needs to update the "last authenticated user" to reflect the new session. Without exported setters, the only workaround is to directly access the internal localStorage keys (dls_last_user_login_id, dls_last_user_display_name), which is fragile and could break if the keys change.

Proposed Solution

Export the existing helper functions from packages/sdks/web-js-sdk/src/index.ts, following the same pattern used for fingerprint helpers:

export {
  getLastUserLoginId,
  getLastUserDisplayName,
  setLastUserLoginId,
  setLastUserDisplayName,
  removeLastUserLoginId,
  removeLastUserDisplayName,
} from './enhancers/withLastLoggedInUser/helpers';

This is a minimal change since the functions already exist and are well-tested.

PR: #1332

Alternative Approach

Another approach would be to use cookies instead of localStorage, which would allow setting the last user from the server side. However, for simplicity we chose the localStorage export approach. If the Descope team prefers the cookie-based solution or has other suggestions, we're open to that as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions