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
20 changes: 13 additions & 7 deletions src/modules/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/modules/auth.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down