From 8813cfbdeccbc21b9d646f62700c62b58998a97a Mon Sep 17 00:00:00 2001 From: Roy Miloh Date: Thu, 11 Dec 2025 15:21:41 -0300 Subject: [PATCH 1/3] login with provider --- src/modules/auth.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/modules/auth.ts b/src/modules/auth.ts index 412b65a..ba477f6 100644 --- a/src/modules/auth.ts +++ b/src/modules/auth.ts @@ -24,6 +24,7 @@ export function createAuthModule( async me() { return axios.get(`/apps/${appId}/entities/User/me`); }, + /** * Update current user data * @param {Object} data - Updated user data @@ -60,6 +61,28 @@ export function createAuthModule( window.location.href = loginUrl; }, + /** + * Redirects the user to a provider's login page + * @param {string} provider - OAuth provider name (e.g., 'google', 'github') + * @param {string} fromUrl - Optional URL to redirect to after successful login (defaults to '/') + * @throws {Error} When not in a browser environment + */ + loginWithProvider(provider: string, fromUrl: string = "/") { + // 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.serverUrl + }/api/apps/auth${providerPath}/login?appId=${appId}&from_url=${encodeURIComponent( + redirectUrl + )}`; + + // Redirect to the provider login page + window.location.href = loginUrl; + }, + /** * Logout the current user * Removes the token from localStorage and optionally redirects to a URL or reloads the page From 970cdebc21357cd9b30adfbfd8a0ce60db094453 Mon Sep 17 00:00:00 2001 From: Roy Miloh Date: Sat, 13 Dec 2025 16:09:24 -0300 Subject: [PATCH 2/3] param --- src/modules/auth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/auth.ts b/src/modules/auth.ts index ba477f6..301cd23 100644 --- a/src/modules/auth.ts +++ b/src/modules/auth.ts @@ -75,7 +75,7 @@ export function createAuthModule( const providerPath = provider === "google" ? "" : `/${provider}`; const loginUrl = `${ options.serverUrl - }/api/apps/auth${providerPath}/login?appId=${appId}&from_url=${encodeURIComponent( + }/api/apps/auth${providerPath}/login?app_id=${appId}&from_url=${encodeURIComponent( redirectUrl )}`; From 76ce6722b390496148c9e51f6302b6b46ffae4dc Mon Sep 17 00:00:00 2001 From: Roy Miloh Date: Fri, 9 Jan 2026 08:45:14 -0300 Subject: [PATCH 3/3] docs --- src/modules/auth.types.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/modules/auth.types.ts b/src/modules/auth.types.ts index 6124f4b..fe349a9 100644 --- a/src/modules/auth.types.ts +++ b/src/modules/auth.types.ts @@ -185,6 +185,28 @@ export interface AuthModule { */ redirectToLogin(nextUrl: string): void; + /** + * Redirects the user to a third-party authentication provider's login page. + * + * Initiates OAuth/SSO login flow with providers like Google, Microsoft, etc. Requires a browser environment and can't be used in the backend. + * + * @param provider - Name of the supported authentication provider (e.g., 'google', 'microsoft'). + * @param fromUrl - URL to redirect to after successful authentication. Defaults to '/'. + * + * @example + * ```typescript + * // Login with Google and return to current page + * base44.auth.loginWithProvider('google', window.location.pathname); + * ``` + * + * @example + * ```typescript + * // Login with GitHub and redirect to dashboard + * base44.auth.loginWithProvider('microsoft', '/dashboard'); + * ``` + */ + loginWithProvider(provider: string, fromUrl?: string): void; + /** * Logs out the current user. *