New Ory Agent Security is now live! Claim your complimentary test drive. Get Started!

Skip to main content

LastUsedMethodStorage

A key-value store for the last used login method. The default keeps the value in window.localStorage. Supply your own to keep it elsewhere.

The storage has to survive page loads, because Ory Elements leaves the page for the identity provider and after a successful sign-in, so an in-memory store loses the choice. Define it outside any component, so that it is the same object on every render, and pass it from a client component, because a server component cannot pass functions.

Example​

This storage keeps the choice in window.sessionStorage until the tab closes. Reading window.sessionStorage throws when the browser blocks site data, so it reads it inside try.

function sessionStore(): Storage | undefined {
try {
return window.sessionStorage
} catch {
return undefined
}
}

export const lastUsedMethodStorage: LastUsedMethodStorage = {
get: async (key) => sessionStore()?.getItem(key) ?? null,
set: async (key, value) => {
sessionStore()?.setItem(key, value)
},
}

Methods​

get()​

get(key: string): Promise<null | string>;

Returns the stored value, or null when nothing is stored.

Parameters​

ParameterTypeDescription
keystringThe storage key.

Returns​

Promise<null | string>


set()​

set(key: string, value: string): Promise<void>;

Stores the value, replacing any previous value.

Parameters​

ParameterTypeDescription
keystringThe storage key.
valuestringThe value to store.

Returns​

Promise<void>