diff --git a/src/modules/auth.ts b/src/modules/auth.ts index d186622..fd3995f 100644 --- a/src/modules/auth.ts +++ b/src/modules/auth.ts @@ -60,13 +60,19 @@ export function createAuthModule( // Build the full redirect URL const redirectUrl = new URL(fromUrl, window.location.origin).toString(); - // Build the provider login URL (google is the default, so no provider path needed) - const providerPath = provider === "google" ? "" : `/${provider}`; - const loginUrl = `${ - options.appBaseUrl - }/api/apps/auth${providerPath}/login?app_id=${appId}&from_url=${encodeURIComponent( - redirectUrl - )}`; + const queryParams = `app_id=${appId}&from_url=${encodeURIComponent(redirectUrl)}`; + + // SSO uses a different URL structure with appId in the path + let authPath: string; + if (provider === "sso") { + authPath = `/apps/${appId}/auth/sso/login`; + } else { + // Google is the default provider, so no provider path segment needed + const providerPath = provider === "google" ? "" : `/${provider}`; + authPath = `/apps/auth${providerPath}/login`; + } + + const loginUrl = `${options.appBaseUrl}/api${authPath}?${queryParams}`; // Redirect to the provider login page window.location.href = loginUrl; diff --git a/src/modules/auth.types.ts b/src/modules/auth.types.ts index 55366ce..d2b57b2 100644 --- a/src/modules/auth.types.ts +++ b/src/modules/auth.types.ts @@ -199,8 +199,9 @@ export interface AuthModule { * - `'microsoft'` - {@link https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow | Microsoft OAuth}. Enable Microsoft in your app's authentication settings before specifying this provider. * - `'facebook'` - {@link https://developers.facebook.com/docs/facebook-login | Facebook Login}. Enable Facebook in your app's authentication settings before using. * - `'apple'` - {@link https://developer.apple.com/sign-in-with-apple/ | Sign in with Apple}. Enable Apple in your app's authentication settings before using this provider. + * - `'sso'` - Enterprise SSO. Enable SSO in your app's authentication settings before using this provider. * - * @param provider - The authentication provider to use: `'google'`, `'microsoft'`, `'facebook'`, or `'apple'`. + * @param provider - The authentication provider to use: `'google'`, `'microsoft'`, `'facebook'`, `'apple'`, or `'sso'`. * @param fromUrl - URL to redirect to after successful authentication. Defaults to `'/'`. * * @example @@ -220,6 +221,12 @@ export interface AuthModule { * // Apple * base44.auth.loginWithProvider('apple', '/dashboard'); * ``` + * + * @example + * ```typescript + * // SSO + * base44.auth.loginWithProvider('sso', '/dashboard'); + * ``` */ loginWithProvider(provider: string, fromUrl?: string): void;