Skip to content

Commit bfbfe62

Browse files
authored
auth: align API with current abilities (#49)
1 parent 5a19f5a commit bfbfe62

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/modules/auth.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ export function createAuthModule(
5757
window.location.href = loginUrl;
5858
},
5959

60+
// Redirects the user to a provider's login page
61+
loginWithProvider(provider: string, fromUrl: string = "/") {
62+
// Build the full redirect URL
63+
const redirectUrl = new URL(fromUrl, window.location.origin).toString();
64+
65+
// Build the provider login URL (google is the default, so no provider path needed)
66+
const providerPath = provider === "google" ? "" : `/${provider}`;
67+
const loginUrl = `${
68+
options.serverUrl
69+
}/api/apps/auth${providerPath}/login?app_id=${appId}&from_url=${encodeURIComponent(
70+
redirectUrl
71+
)}`;
72+
73+
// Redirect to the provider login page
74+
window.location.href = loginUrl;
75+
},
76+
6077
// Logout the current user
6178
// Removes the token from localStorage and optionally redirects to a URL or reloads the page
6279
logout(redirectUrl?: string) {

src/modules/auth.types.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,28 @@ export interface AuthModule {
185185
*/
186186
redirectToLogin(nextUrl: string): void;
187187

188+
/**
189+
* Redirects the user to a third-party authentication provider's login page.
190+
*
191+
* Initiates OAuth/SSO login flow with providers like Google, Microsoft, etc. Requires a browser environment and can't be used in the backend.
192+
*
193+
* @param provider - Name of the supported authentication provider (e.g., 'google', 'microsoft').
194+
* @param fromUrl - URL to redirect to after successful authentication. Defaults to '/'.
195+
*
196+
* @example
197+
* ```typescript
198+
* // Login with Google and return to current page
199+
* base44.auth.loginWithProvider('google', window.location.pathname);
200+
* ```
201+
*
202+
* @example
203+
* ```typescript
204+
* // Login with GitHub and redirect to dashboard
205+
* base44.auth.loginWithProvider('microsoft', '/dashboard');
206+
* ```
207+
*/
208+
loginWithProvider(provider: string, fromUrl?: string): void;
209+
188210
/**
189211
* Logs out the current user.
190212
*

0 commit comments

Comments
 (0)