Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { createClient } from "./create-client";
export { getClaims } from "./utils/session-data";
export {
User,
AuthenticationMethod,
AuthenticationResponse,
OnRefreshResponse,
JWTPayload,
Expand Down
25 changes: 25 additions & 0 deletions src/interfaces/authentication-response.interface.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
import { User, UserRaw } from "./user.interface";
import { Impersonator, ImpersonatorRaw } from "./impersonator.interface";

export type AuthenticationMethod =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the complete list of authentication methods is

SSO
Password
Passkey
AppleOAuth
BitbucketOAuth
CrossAppAuth
DiscordOAuth
ExternalAuth
GitHubOAuth
GitLabOAuth
GoogleOAuth
LinkedInOAuth
MicrosoftOAuth
SalesforceOAuth
SlackOAuth
VercelMarketplaceOAuth
VercelOAuth
XeroOAuth
MagicAuth
Impersonation
MigratedSession

| "SSO"
| "Password"
| "Passkey"
| "AppleOAuth"
| "BitbucketOAuth"
| "CrossAppAuth"
| "DiscordOAuth"
| "ExternalAuth"
| "GitHubOAuth"
| "GitLabOAuth"
| "GoogleOAuth"
| "LinkedInOAuth"
| "MicrosoftOAuth"
| "SalesforceOAuth"
| "SlackOAuth"
| "VercelMarketplaceOAuth"
| "VercelOAuth"
| "XeroOAuth"
| "MagicAuth"
| "Impersonation"
| "MigratedSession";

export interface AuthenticationResponse {
user: User;
accessToken: string;
refreshToken: string;
authenticationMethod: AuthenticationMethod;
organizationId?: string;
impersonator?: Impersonator;
}
Expand All @@ -15,6 +39,7 @@ export interface AuthenticationResponseRaw {
user: UserRaw;
access_token: string;
refresh_token: string;
authentication_method: AuthenticationMethod;
organization_id?: string;
impersonator?: ImpersonatorRaw;
}
1 change: 1 addition & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type {
AuthenticationMethod,
AuthenticationResponse,
AuthenticationResponseRaw,
OnRefreshResponse,
Expand Down
2 changes: 2 additions & 0 deletions src/serializers/authentication-response.serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const deserializeAuthenticationResponse = (
organization_id,
access_token,
refresh_token,
authentication_method,
impersonator,
...rest
} = authenticationResponse;
Expand All @@ -21,6 +22,7 @@ export const deserializeAuthenticationResponse = (
organizationId: organization_id,
accessToken: access_token,
refreshToken: refresh_token,
authenticationMethod: authentication_method,
impersonator,
...rest,
};
Expand Down
1 change: 1 addition & 0 deletions src/utils/session-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe("setSessionData", () => {
setSessionData({
accessToken: validToken,
refreshToken: "refresh_token",
authenticationMethod: "Password",
user: mockUser,
});
expect(memoryStorage.getItem(storageKeys.accessToken)).toBe(validToken);
Expand Down
4 changes: 3 additions & 1 deletion src/utils/session-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ export function setSessionData(
data: AuthenticationResponse,
{ devMode = false } = {},
) {
const { user, accessToken, refreshToken } = data;
const { user, accessToken, refreshToken, authenticationMethod } = data;
memoryStorage.setItem(storageKeys.user, user);
memoryStorage.setItem(storageKeys.accessToken, accessToken);
memoryStorage.setItem(storageKeys.authenticationMethod, authenticationMethod);
(devMode ? window.localStorage : memoryStorage).setItem(
storageKeys.refreshToken,
refreshToken,
Expand All @@ -34,6 +35,7 @@ export function setSessionData(
export function removeSessionData({ devMode = false } = {}) {
memoryStorage.removeItem(storageKeys.user);
memoryStorage.removeItem(storageKeys.accessToken);
memoryStorage.removeItem(storageKeys.authenticationMethod);
(devMode ? window.localStorage : memoryStorage).removeItem(
storageKeys.refreshToken,
);
Expand Down
1 change: 1 addition & 0 deletions src/utils/storage-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export const storageKeys = {
accessToken: "workos:access-token",
refreshToken: "workos:refresh-token",
expiresAt: "workos:expires-at",
authenticationMethod: "workos:authentication-method",
} as const;