diff --git a/examples/nextjs/README.md b/examples/nextjs/README.md
index de163b09e..50722512d 100644
--- a/examples/nextjs/README.md
+++ b/examples/nextjs/README.md
@@ -13,10 +13,9 @@ These are the different pages that you will find in this application:
- `/signup` : Signup component page
- `/dashboard` : The dashboard has three nested routes:
- `/` : User Details page which uses `@corbado/node-sdk` to fetch complete details of the currently logged-in user.
- - `/session-details` : this page deserializes the short session and show cases the details stored in the short session.
+ - `/session-details` : this page deserializes the session-token and show cases the details stored in the session-token.
- `/passkey-list` : this page uses the `@corbado/react`'s `` component to showcase its use
## Points to Note
- When you use a component from `@corbado/react` either a UI component or a Provider component you need to `use client` for client side rendering as the components make use of react contexts.
-- For using `` with NextJS application we need to set `setShortSessionCookie` to true. It's important to set this since Corbado uses refresh tokens to keep the user logged in and by storing short session cookies, the user will be able to stay logged in even if the token is refreshed
diff --git a/examples/nextjs/app/providers.tsx b/examples/nextjs/app/providers.tsx
index e5a5d6ef5..cf89cb526 100644
--- a/examples/nextjs/app/providers.tsx
+++ b/examples/nextjs/app/providers.tsx
@@ -7,9 +7,6 @@ export function Providers({ children }: { children: React.ReactNode }) {
{children}
diff --git a/examples/nextjs/app/ui/dashboard/current-user.tsx b/examples/nextjs/app/ui/dashboard/current-user.tsx
index 27d5b421a..fa5b47edf 100644
--- a/examples/nextjs/app/ui/dashboard/current-user.tsx
+++ b/examples/nextjs/app/ui/dashboard/current-user.tsx
@@ -4,9 +4,9 @@ import createNodeSDK from '@/app/utils/createNodeSDK';
export default async function CurrentUser() {
const cookieStore = cookies();
- const session = cookieStore.get('cbo_short_session');
+ const sessionTokenCookie = cookieStore.get('cbo_session_token');
const sdk = createNodeSDK();
- const currentSessionUser = await sdk.sessions().getCurrentUser(session?.value ?? '');
+ const currentSessionUser = await sdk.sessions().getCurrentUser(sessionTokenCookie?.value ?? '');
const userResp = await sdk.users().get(currentSessionUser?.getID() ?? '');
const user = userResp.data;
const activeEmail = user.emails.find(email => email.status === 'active');
diff --git a/examples/nextjs/app/ui/dashboard/session-details.tsx b/examples/nextjs/app/ui/dashboard/session-details.tsx
index 224da75f7..b4c9d58c4 100644
--- a/examples/nextjs/app/ui/dashboard/session-details.tsx
+++ b/examples/nextjs/app/ui/dashboard/session-details.tsx
@@ -3,16 +3,16 @@ import { cookies } from 'next/headers';
export default function SessionDetails() {
const cookieStore = cookies();
- const session = cookieStore.get('cbo_short_session');
+ const sessionTokenCookie = cookieStore.get('cbo_session_token');
- const decodedShortSession = jwtDecode(session?.value ?? '');
- const serializedDecodedShortSession = JSON.stringify(decodedShortSession, null, 2);
+ const decodedSessionToken = jwtDecode(sessionTokenCookie?.value ?? '');
+ const serializedDecodedSessionToken = JSON.stringify(decodedSessionToken, null, 2);
return (
<>
-
This is your shortSession:
-
{serializedDecodedShortSession}
+
This is your sessionToken:
+
{serializedDecodedSessionToken}
>
);
diff --git a/examples/nextjs/app/ui/right-intro-section.tsx b/examples/nextjs/app/ui/right-intro-section.tsx
index c9e78cb31..4ec6ca386 100644
--- a/examples/nextjs/app/ui/right-intro-section.tsx
+++ b/examples/nextjs/app/ui/right-intro-section.tsx
@@ -6,9 +6,9 @@ import Image from 'next/image';
export default async function RightIntroSection() {
const cookieStore = cookies();
- const sessionCookie = cookieStore.get('cbo_short_session');
- const shortSession = sessionCookie?.value;
- const isSessionValid = await validateSession(shortSession);
+ const sessionTokenCookie = cookieStore.get('cbo_session_token');
+ const sessionToken = sessionTokenCookie?.value;
+ const isSessionValid = await validateSession(sessionToken);
if (isSessionValid) {
return (
diff --git a/examples/nextjs/app/utils/validateSession.ts b/examples/nextjs/app/utils/validateSession.ts
index b571b3b0b..ed97c96f6 100644
--- a/examples/nextjs/app/utils/validateSession.ts
+++ b/examples/nextjs/app/utils/validateSession.ts
@@ -1,18 +1,18 @@
import { jwtDecode } from 'jwt-decode';
import createNodeSDK from './createNodeSDK';
-export default async function validateSession(shortSession: string | undefined) {
- if (!shortSession) {
+export default async function validateSession(sessionToken: string | undefined) {
+ if (!sessionToken) {
return false;
}
const sdk = createNodeSDK();
- const verifiedSession = await sdk.sessions().validateShortSessionValue(shortSession);
+ const verifiedSession = await sdk.sessions().validateShortSessionValue(sessionToken);
if (!verifiedSession.isAuthenticated()) {
return false;
}
- const decodedShortSession = jwtDecode(shortSession);
- return !!decodedShortSession.exp && decodedShortSession.exp > Date.now() / 1000;
+ const decodedSessionToken = jwtDecode(sessionToken);
+ return !!decodedSessionToken.exp && decodedSessionToken.exp > Date.now() / 1000;
}
diff --git a/examples/nextjs/middleware.ts b/examples/nextjs/middleware.ts
index 9476a3c44..be1086ad7 100644
--- a/examples/nextjs/middleware.ts
+++ b/examples/nextjs/middleware.ts
@@ -15,9 +15,9 @@ export async function middleware(request: NextRequest) {
return NextResponse.next();
}
- const cookie = request.cookies.get('cbo_short_session');
- const shortSession = cookie?.value;
- const isSessionValid = await validateSession(shortSession);
+ const cookie = request.cookies.get('cbo_session_token');
+ const sessionToken = cookie?.value;
+ const isSessionValid = await validateSession(sessionToken);
if (isSessionValid && routes.authPaths.includes(url.pathname)) {
url.pathname = '/dashboard';
diff --git a/packages/react/src/contexts/CorbadoSessionContext.tsx b/packages/react/src/contexts/CorbadoSessionContext.tsx
index 78bfe5766..2fb203055 100644
--- a/packages/react/src/contexts/CorbadoSessionContext.tsx
+++ b/packages/react/src/contexts/CorbadoSessionContext.tsx
@@ -10,11 +10,6 @@ const missingImplementation = (): never => {
export interface CorbadoSessionContextProps {
corbadoApp: CorbadoApp | undefined;
- /**
- * @deprecated Use sessionToken instead
- */
- shortSession: string | undefined;
-
sessionToken: string | undefined;
loading: boolean;
isAuthenticated: boolean;
@@ -29,7 +24,6 @@ export interface CorbadoSessionContextProps {
export const initialContext: CorbadoSessionContextProps = {
corbadoApp: undefined,
- shortSession: undefined,
sessionToken: undefined,
loading: true,
isAuthenticated: false,
diff --git a/packages/react/src/contexts/CorbadoSessionProvider.tsx b/packages/react/src/contexts/CorbadoSessionProvider.tsx
index c3b8b6c43..ff4833fc0 100644
--- a/packages/react/src/contexts/CorbadoSessionProvider.tsx
+++ b/packages/react/src/contexts/CorbadoSessionProvider.tsx
@@ -22,7 +22,7 @@ export const CorbadoSessionProvider: FC = ({
const [loading, setLoading] = useState(true);
const [user, setUser] = useState();
const [isAuthenticated, setIsAuthenticated] = useState(false);
- const [shortSession, setShortSession] = useState();
+ const [sessionToken, setSessionToken] = useState();
const init = async () => {
setLoading(true);
@@ -46,14 +46,14 @@ export const CorbadoSessionProvider: FC = ({
setIsAuthenticated(!!value);
});
- const shortSessionSub = corbadoApp.sessionService.shortSessionChanges.subscribe((value: string | undefined) => {
- setShortSession(value);
+ const sessionTokenSub = corbadoApp.sessionService.sessionTokenChanges.subscribe((value: string | undefined) => {
+ setSessionToken(value);
});
return () => {
userSub.unsubscribe();
authStateSub.unsubscribe();
- shortSessionSub.unsubscribe();
+ sessionTokenSub.unsubscribe();
};
}, []);
@@ -86,13 +86,10 @@ export const CorbadoSessionProvider: FC = ({
[corbadoApp],
);
- const sessionToken = shortSession;
-
return (
= new BehaviorSubject(undefined);
- #shortSessionChanges: BehaviorSubject = new BehaviorSubject(undefined);
+ #sessionTokenChanges: BehaviorSubject = new BehaviorSubject(undefined);
#authStateChanges: BehaviorSubject = new BehaviorSubject(AuthState.LoggedOut);
- constructor(projectId: string, setShortSessionCookie: boolean, isPreviewMode: boolean, frontendApiUrlSuffix: string) {
+ constructor(projectId: string, isPreviewMode: boolean, frontendApiUrlSuffix: string) {
this.#projectId = projectId;
+ this.#isPreviewMode = isPreviewMode;
this.#frontendApiUrlSuffix = frontendApiUrlSuffix;
+
this.#webAuthnService = new WebAuthnService();
- this.#longSession = undefined;
- this.#setShortSessionCookie = setShortSessionCookie;
- this.#isPreviewMode = isPreviewMode;
+ this.#refreshToken = undefined;
}
/**
- * Initializes the SessionService by registering a callback that is called when the shortSession changes.
+ * Initializes the SessionService by registering a callback that is called when the session-token changes.
*/
async init(): Promise {
const sessionConfig = await this.#loadSessionConfig();
@@ -87,23 +97,23 @@ export class SessionService {
}
this.#sessionConfig = sessionConfig.val;
- this.#longSession = SessionService.#getLongSessionToken();
- this.#shortSession = SessionService.#getShortTermSessionToken();
+ this.#refreshToken = SessionService.#getRefreshToken();
+ this.#sessionToken = SessionService.#getSessionToken();
// if the session is valid, we emit it
- if (this.#shortSession && this.#shortSession.isValidForXMoreSeconds(0)) {
- log.debug('emit shortsession', this.#shortSession);
- this.#onShortSessionChange(this.#shortSession);
+ if (this.#sessionToken && this.#sessionToken.isValidForXMoreSeconds(0)) {
+ log.debug('emit session-token', this.#sessionToken);
+ this.#onSessionTokenChange(this.#sessionToken);
} else {
await this.#handleRefreshRequest();
}
- this.#setApisV2(this.#longSession);
+ this.#setApisV2(this.#refreshToken);
// init scheduled session refresh
this.#refreshIntervalId = setInterval(() => {
void this.#handleRefreshRequest();
- }, shortSessionRefreshIntervalMs);
+ }, sessionTokenRefreshIntervalMs);
document.addEventListener('visibilitychange', () => {
this.#handleVisibilityChange();
@@ -113,11 +123,11 @@ export class SessionService {
}
/**
- * Getter method for retrieving the short term session token.
- * @returns The short term session token or null if it's not set.
+ * Getter method for retrieving the session-token.
+ * @returns The session-token or null if it's not set.
*/
- public get shortSession() {
- return this.#shortSession;
+ public get sessionToken() {
+ return this.#sessionToken;
}
/**
@@ -125,11 +135,11 @@ export class SessionService {
* @returns The username or null if it's not set.
*/
public getUser(): SessionUser | undefined {
- if (!this.#shortSession) {
+ if (!this.#sessionToken) {
return;
}
- const sessionParts = this.#shortSession.value.split('.');
+ const sessionParts = this.#sessionToken.value.split('.');
return JSON.parse(base64decode(sessionParts[1]));
}
@@ -142,10 +152,10 @@ export class SessionService {
}
/**
- * Exposes changes to the shortSession
+ * Exposes changes to the session-token.
*/
- get shortSessionChanges(): BehaviorSubject {
- return this.#shortSessionChanges;
+ get sessionTokenChanges(): BehaviorSubject {
+ return this.#sessionTokenChanges;
}
/**
@@ -215,40 +225,41 @@ export class SessionService {
});
this.clear();
- this.#onShortSessionChange(undefined);
+ this.#onSessionTokenChange(undefined);
}
- #onShortSessionChange(shortSession: ShortSession | undefined) {
+ #onSessionTokenChange(sessionToken: SessionToken | undefined) {
const user = this.getUser();
- if (user && shortSession) {
- this.#shortSessionChanges.next(shortSession.value);
+ if (user && sessionToken) {
+ this.#sessionTokenChanges.next(sessionToken.value);
this.#updateAuthState(AuthState.LoggedIn);
this.#updateUser(user);
} else {
- console.log('user is logged out', user, shortSession);
- this.#shortSessionChanges.next(undefined);
+ log.debug('user is logged out', user, sessionToken);
+
+ this.#sessionTokenChanges.next(undefined);
this.#updateAuthState(AuthState.LoggedOut);
this.#updateUser(undefined);
}
}
/** Method to set Session
- * It sets the short term session token, long term session token, and username for the Corbado Application.
- * @param shortSessionValue The short term session token to be set.
- * @param longSession The long term session token to be set.
+ * It sets the session-token, refresh-token, and username for the Corbado Application.
+ * @param sessionToken The session-token to be set.
+ * @param refreshToken The refresh-token to be set.
*/
- setSession(shortSessionValue: string, longSession: string | undefined) {
- const shortSession = new ShortSession(shortSessionValue);
+ setSession(sessionToken: string, refreshToken: string | undefined) {
+ const sessionTokenModel = new SessionToken(sessionToken);
- this.#setShortTermSessionToken(shortSession);
- this.#setApisV2(longSession ?? '');
+ this.#setSessionToken(sessionTokenModel);
+ this.#setApisV2(refreshToken ?? '');
- this.#onShortSessionChange(shortSession);
- this.#setLongSessionToken(longSession);
+ this.#onSessionTokenChange(sessionTokenModel);
+ this.#setRefreshToken(refreshToken);
}
- #setApisV2(longSession: string): void {
+ #setApisV2(refreshToken: string): void {
let frontendApiUrl = this.#getSessionConfig().frontendApiUrl;
if (!frontendApiUrl || frontendApiUrl.length === 0) {
frontendApiUrl = this.#getDefaultFrontendApiUrl();
@@ -258,14 +269,14 @@ export class SessionService {
apiKey: this.#projectId,
basePath: frontendApiUrl,
});
- const axiosInstance = this.#createAxiosInstanceV2(longSession);
+ const axiosInstance = this.#createAxiosInstanceV2(refreshToken);
this.#usersApi = new UsersApi(config, frontendApiUrl, axiosInstance);
}
- // usually sessionService needs a longSession for all it's requests
+ // usually sessionService needs a refresh-token for all it's requests
// just the initial request to fetch the sessionConfig doesn't need it
- #createAxiosInstanceV2(longSession?: string): AxiosInstance {
+ #createAxiosInstanceV2(refreshToken?: string): AxiosInstance {
const corbadoVersion = {
name: 'web-core',
sdkVersion: packageVersion,
@@ -283,10 +294,10 @@ export class SessionService {
headers['X-Corbado-Flags'] = this.#buildCorbadoFlags();
let axiosInstance: AxiosInstance;
- if (longSession) {
+ if (refreshToken) {
axiosInstance = axios.create({
withCredentials: true,
- headers: { ...headers, Authorization: `Bearer ${longSession}` },
+ headers: { ...headers, Authorization: `Bearer ${refreshToken}` },
});
} else {
axiosInstance = axios.create({
@@ -309,11 +320,11 @@ export class SessionService {
/**
* Method to delete Session.
- * It deletes the short term session token, long term session token, and username for the Corbado Application.
+ * It deletes the session-token, refresh-token and username for the Corbado Application.
*/
clear() {
- this.#deleteShortTermSessionToken();
- this.#deleteLongSessionToken();
+ this.#deleteSessionToken();
+ this.#deleteRefreshToken();
if (this.#refreshIntervalId) {
clearInterval(this.#refreshIntervalId);
@@ -321,24 +332,12 @@ export class SessionService {
}
/**
- * Gets the short term session token.
+ * Gets the session-token.
*/
- static #getShortTermSessionToken(): ShortSession | undefined {
- const localStorageValue = localStorage.getItem(shortSessionKey);
- if (localStorageValue) {
- return new ShortSession(localStorageValue);
- }
-
- // Get new session-token
+ static #getSessionToken(): SessionToken | undefined {
const sessionToken = this.#getCookieValue(sessionTokenKey);
if (sessionToken) {
- return new ShortSession(sessionToken);
- }
-
- // Fallback for deprecated short-term session
- const shortSession = this.#getCookieValue(shortSessionKey);
- if (shortSession) {
- return new ShortSession(shortSession);
+ return new SessionToken(sessionToken);
}
return undefined;
@@ -355,100 +354,76 @@ export class SessionService {
}
/**
- * Deletes the long term session token cookie for dev environment in localStorage.
+ * Deletes the refresh-token (see property for more details why this exists).
*/
- #deleteLongSessionToken(): void {
- localStorage.removeItem(longSessionKey);
- this.#longSession = '';
+ #deleteRefreshToken(): void {
+ localStorage.removeItem(refreshTokenKey);
+ this.#refreshToken = '';
}
/**
- * Gets the long term session token.
+ * Gets the refresh-token (see property for more details why this exists).
*/
- static #getLongSessionToken() {
- return (localStorage.getItem(longSessionKey) as string) ?? '';
+ static #getRefreshToken() {
+ return (localStorage.getItem(refreshTokenKey) as string) ?? '';
}
/**
- * Sets a short term session token.
+ * Sets the session-token.
* @param value
*/
- #setShortTermSessionToken(value: ShortSession): void {
- localStorage.setItem(shortSessionKey, value.toString());
- this.#shortSession = value;
+ #setSessionToken(value: SessionToken): void {
+ this.#sessionToken = value;
- if (this.#setShortSessionCookie) {
- const cookieConfig = this.#getShortSessionCookieConfig();
-
- document.cookie = this.#getShortSessionCookieString(cookieConfig, value);
- document.cookie = this.#getSessionTokenCookieString(cookieConfig, value);
- }
+ const cookieConfig = this.#getSessionTokenCookieConfig();
+ document.cookie = this.#getSessionTokenCookieString(cookieConfig, value);
}
/**
- * Deletes the short term session token.
+ * Deletes the session-token.
*/
- #deleteShortTermSessionToken(): void {
- localStorage.removeItem(shortSessionKey);
- this.#shortSession = undefined;
+ #deleteSessionToken(): void {
+ this.#sessionToken = undefined;
- if (this.#setShortSessionCookie) {
- const cookieConfig = this.#getShortSessionCookieConfig();
-
- document.cookie = this.#getDeleteShortSessionCookieString(cookieConfig);
- document.cookie = this.#getDeleteSessionTokenCookieString(cookieConfig);
- }
+ const cookieConfig = this.#getSessionTokenCookieConfig();
+ document.cookie = this.#getDeleteSessionTokenCookieString(cookieConfig);
}
- #getShortSessionCookieString(config: ShortSessionCookieConfig, value: ShortSession): string {
- const expires = new Date(Date.now() + config.lifetimeSeconds * 1000).toUTCString();
- return `${shortSessionKey}=${value}; domain=${config.domain}; ${config.secure ? 'secure; ' : ''}sameSite=${
- config.sameSite
- }; path=${config.path}; expires=${expires}`;
- }
-
- #getSessionTokenCookieString(config: ShortSessionCookieConfig, value: ShortSession): string {
+ #getSessionTokenCookieString(config: SessionTokenCookieConfig, value: SessionToken): string {
const expires = new Date(Date.now() + config.lifetimeSeconds * 1000).toUTCString();
return `${sessionTokenKey}=${value}; domain=${config.domain}; ${config.secure ? 'secure; ' : ''}sameSite=${
config.sameSite
}; path=${config.path}; expires=${expires}`;
}
- #getDeleteShortSessionCookieString(config: ShortSessionCookieConfig) {
- return `${shortSessionKey}=; domain=${config.domain}; ${config.secure ? 'secure; ' : ''}sameSite=${
- config.sameSite
- }; path=${config.path}; expires=${new Date().toUTCString()}`;
- }
-
- #getDeleteSessionTokenCookieString(config: ShortSessionCookieConfig) {
+ #getDeleteSessionTokenCookieString(config: SessionTokenCookieConfig) {
return `${sessionTokenKey}=; domain=${config.domain}; ${config.secure ? 'secure; ' : ''}sameSite=${
config.sameSite
}; path=${config.path}; expires=${new Date().toUTCString()}`;
}
/**
- * Sets a long term session token for dev environment in localStorage.
- * For production, it sets a cookie.
+ * Sets the refresh-token (see property for more details why this exists).
*/
- #setLongSessionToken(longSessionToken: string | undefined): void {
- if (!longSessionToken) {
+ #setRefreshToken(refreshToken: string | undefined): void {
+ if (!refreshToken) {
return;
}
- localStorage.setItem(longSessionKey, longSessionToken);
- this.#longSession = longSessionToken;
+ localStorage.setItem(refreshTokenKey, refreshToken);
+ this.#refreshToken = refreshToken;
}
async #handleRefreshRequest() {
- // no shortSession => user is not logged in => nothing to refresh
- if (!this.#shortSession) {
+ // no session-token => user is not logged in => nothing to refresh
+ if (!this.#sessionToken) {
log.debug('session refresh: no refresh, user not logged in');
return;
}
// refresh, token too old
- if (!this.#shortSession.isValidForXMoreSeconds(shortSessionRefreshBeforeExpirationSeconds)) {
+ if (!this.#sessionToken.isValidForXMoreSeconds(sessionTokenRefreshBeforeExpirationSeconds)) {
await this.#refresh();
}
@@ -463,7 +438,7 @@ export class SessionService {
try {
const options: AxiosRequestConfig = {
headers: {
- Authorization: `Bearer ${this.#longSession}`,
+ Authorization: `Bearer ${this.#refreshToken}`,
},
};
const response = await this.#usersApi.currentUserSessionRefresh(options);
@@ -472,12 +447,12 @@ export class SessionService {
return;
}
- if (!response.data.shortSession) {
- log.warn('refresh error, missing short session');
+ if (!response.data.sessionToken) {
+ log.warn('refresh error, missing session-token');
return;
}
- this.setSession(response.data.shortSession, undefined);
+ this.setSession(response.data.sessionToken, undefined);
} catch (e) {
// if it's a network error, we should do a retry
// for all other errors, we should log out the user
@@ -535,8 +510,8 @@ export class SessionService {
return this.#sessionConfig;
};
- #getShortSessionCookieConfig = (): ShortSessionCookieConfig => {
- const cfg = this.#getSessionConfig().shortSessionCookieConfig;
+ #getSessionTokenCookieConfig = (): SessionTokenCookieConfig => {
+ const cfg = this.#getSessionConfig().sessionTokenCookieConfig;
if (!cfg) {
throw CorbadoError.invalidConfig();
}
diff --git a/packages/web-core/src/services/index.ts b/packages/web-core/src/services/index.ts
index f8eed6fcb..c11e410e7 100644
--- a/packages/web-core/src/services/index.ts
+++ b/packages/web-core/src/services/index.ts
@@ -1,9 +1,9 @@
import type { CorbadoAppParams } from '@corbado/types';
import type { Result } from 'ts-results';
-import { Err, Ok } from 'ts-results';
+import { Ok } from 'ts-results';
import type { CorbadoError } from '../utils';
-import { defaultTimeout, NonRecoverableError } from '../utils';
+import { defaultTimeout } from '../utils';
import { ProcessService } from './ProcessService';
import { SessionService } from './SessionService';
@@ -28,17 +28,12 @@ export class CorbadoApp {
projectId,
apiTimeout = defaultTimeout,
frontendApiUrlSuffix = 'frontendapi.corbado.io',
- setShortSessionCookie = true,
isPreviewMode = false,
} = corbadoParams;
+
this.#projectId = projectId;
this.#authProcessService = new ProcessService(this.#projectId, apiTimeout, isPreviewMode, frontendApiUrlSuffix);
- this.#sessionService = new SessionService(
- this.#projectId,
- setShortSessionCookie,
- isPreviewMode,
- frontendApiUrlSuffix,
- );
+ this.#sessionService = new SessionService(this.#projectId, isPreviewMode, frontendApiUrlSuffix);
}
get authProcessService() {
@@ -54,8 +49,10 @@ export class CorbadoApp {
* It fetches the project configuration and initializes the services.
*/
async init(): Promise> {
+ // This can be improved by using the Err() type. Then we need to decide how to present the
+ // error (print it to the browser console, render it in the component, do both etc.)
if (!this.#validateProjectId(this.#projectId)) {
- return Err(new NonRecoverableError('Invalid project ID'));
+ throw new Error(`Invalid project ID '${this.#projectId}'`);
}
await this.#sessionService.init();
diff --git a/packages/web-js/src/core/Corbado.ts b/packages/web-js/src/core/Corbado.ts
index 84f1f4cfc..d1dcfb2b6 100644
--- a/packages/web-js/src/core/Corbado.ts
+++ b/packages/web-js/src/core/Corbado.ts
@@ -15,26 +15,12 @@ export class Corbado {
return this.#getCorbadoAppState().user;
}
- /**
- * @deprecated Use sessionToken() instead
- */
- get shortSession() {
- return this.#getCorbadoAppState().shortSession;
- }
-
get sessionToken() {
- return this.#getCorbadoAppState().shortSession;
- }
-
- /**
- * @deprecated Use sessionTokenChanges() instead
- */
- get shortSessionChanges() {
- return this.#getCorbadoAppState().shortSessionChanges;
+ return this.#getCorbadoAppState().sessionToken;
}
get sessionTokenChanges() {
- return this.#getCorbadoAppState().shortSessionChanges;
+ return this.#getCorbadoAppState().sessionTokenChanges;
}
get userChanges() {
diff --git a/packages/web-js/src/models/CorbadoAppState.ts b/packages/web-js/src/models/CorbadoAppState.ts
index 1f05d5528..3fb225150 100644
--- a/packages/web-js/src/models/CorbadoAppState.ts
+++ b/packages/web-js/src/models/CorbadoAppState.ts
@@ -7,7 +7,7 @@ import type { CorbadoConfig } from '../types/core';
export class CorbadoAppState {
#corbadoApp: CorbadoApp;
#corbadoAppProps: CorbadoConfig;
- #shortSession?: string;
+ #sessionToken?: string;
#isAuthenticated?: boolean;
#user?: SessionUser;
#globalError?: NonRecoverableError;
@@ -15,8 +15,8 @@ export class CorbadoAppState {
constructor(corbadoAppProps: CorbadoConfig) {
const corbadoApp = new CorbadoApp(corbadoAppProps);
- corbadoApp.sessionService.shortSessionChanges.subscribe(value => {
- this.#shortSession = value;
+ corbadoApp.sessionService.sessionTokenChanges.subscribe(value => {
+ this.#sessionToken = value;
});
corbadoApp.sessionService.userChanges.subscribe(value => {
@@ -49,12 +49,12 @@ export class CorbadoAppState {
return this.#corbadoAppProps;
}
- get shortSession() {
- return this.#shortSession;
+ get sessionToken() {
+ return this.#sessionToken;
}
- get shortSessionChanges() {
- return this.#corbadoApp.sessionService.shortSessionChanges;
+ get sessionTokenChanges() {
+ return this.#corbadoApp.sessionService.sessionTokenChanges;
}
get isAuthenticated() {
diff --git a/playground/web-js-script/index.html b/playground/web-js-script/index.html
index 1ef0d961c..51b9df75f 100644
--- a/playground/web-js-script/index.html
+++ b/playground/web-js-script/index.html
@@ -28,7 +28,6 @@
projectId: projectId,
frontendApiUrlSuffix: 'frontendapi.cloud.corbado-staging.io',
darkMode: 'auto',
- setShortSessionCookie: true,
});
}
diff --git a/playground/web-js/src/scripts/index.js b/playground/web-js/src/scripts/index.js
index cb0a46360..186d64627 100644
--- a/playground/web-js/src/scripts/index.js
+++ b/playground/web-js/src/scripts/index.js
@@ -15,7 +15,6 @@ async function loadPage() {
projectId: projectId,
frontendApiUrlSuffix: CORBADO_FRONTEND_API_URL_SUFFIX,
darkMode: 'auto',
- setShortSessionCookie: true,
});
}