clefbase 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.d.ts +6 -26
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +12 -31
- package/dist/app.js.map +1 -1
- package/dist/auth/index.d.ts +63 -114
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +97 -176
- package/dist/auth/index.js.map +1 -1
- package/dist/cli-src/cli/api.js +14 -14
- package/dist/cli-src/cli/commands/deploy.js +84 -16
- package/dist/cli-src/cli/commands/init.js +644 -19
- package/dist/cli-src/cli/config.js +0 -1
- package/dist/cli-src/cli/index.js +48 -9
- package/dist/cli.js +756 -58
- package/dist/hosting/index.d.ts +8 -98
- package/dist/hosting/index.d.ts.map +1 -1
- package/dist/hosting/index.js +37 -95
- package/dist/hosting/index.js.map +1 -1
- package/dist/index.d.ts +14 -60
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -65
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +0 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/app.d.ts
CHANGED
|
@@ -44,10 +44,10 @@ export declare class ClefbaseApp {
|
|
|
44
44
|
*
|
|
45
45
|
* @example
|
|
46
46
|
* const app = initClefbase({
|
|
47
|
-
* serverUrl:
|
|
48
|
-
* projectId:
|
|
49
|
-
* apiKey:
|
|
50
|
-
*
|
|
47
|
+
* serverUrl: "https://api.cleforyx.com",
|
|
48
|
+
* projectId: "swoove-md3",
|
|
49
|
+
* apiKey: "cfx_...",
|
|
50
|
+
* // gatewayUrl defaults to "https://auth.cleforyx.com"
|
|
51
51
|
* });
|
|
52
52
|
*/
|
|
53
53
|
export declare function initClefbase(config: ClefbaseConfig, name?: string): ClefbaseApp;
|
|
@@ -67,7 +67,7 @@ export declare function getHosting(app?: ClefbaseApp): ClefbaseHosting;
|
|
|
67
67
|
* @example
|
|
68
68
|
* import { initClefbase, getFunctions, httpsCallable } from "clefbase";
|
|
69
69
|
*
|
|
70
|
-
* const app = initClefbase({ serverUrl, projectId, apiKey
|
|
70
|
+
* const app = initClefbase({ serverUrl, projectId, apiKey });
|
|
71
71
|
* const fns = getFunctions(app);
|
|
72
72
|
*
|
|
73
73
|
* const greet = httpsCallable<{ name: string }, { message: string }>(fns, "greetUser");
|
|
@@ -80,33 +80,13 @@ export declare function getFunctions(app?: ClefbaseApp): ClefbaseFunctions;
|
|
|
80
80
|
* @example
|
|
81
81
|
* import { initClefbase, getAI } from "clefbase";
|
|
82
82
|
*
|
|
83
|
-
* const app = initClefbase({ serverUrl, projectId, apiKey
|
|
83
|
+
* const app = initClefbase({ serverUrl, projectId, apiKey });
|
|
84
84
|
* const ai = getAI(app);
|
|
85
85
|
*
|
|
86
|
-
* // Text generation
|
|
87
86
|
* const { content } = await ai.text({
|
|
88
87
|
* model: "claude-sonnet-4-5",
|
|
89
88
|
* prompt: "Explain closures in JavaScript",
|
|
90
89
|
* });
|
|
91
|
-
*
|
|
92
|
-
* // Image generation — saved to project Storage automatically
|
|
93
|
-
* const { files } = await ai.image({
|
|
94
|
-
* model: "imagen-3.0-generate-002",
|
|
95
|
-
* prompt: "A futuristic cityscape at sunset",
|
|
96
|
-
* });
|
|
97
|
-
*
|
|
98
|
-
* // Video generation
|
|
99
|
-
* const { status, files: videoFiles } = await ai.video({
|
|
100
|
-
* model: "veo-2.0-generate-001",
|
|
101
|
-
* prompt: "A dog running on a beach",
|
|
102
|
-
* durationSeconds: 5,
|
|
103
|
-
* });
|
|
104
|
-
*
|
|
105
|
-
* // Embeddings
|
|
106
|
-
* const { embeddings } = await ai.embedding({
|
|
107
|
-
* model: "text-embedding-004",
|
|
108
|
-
* input: ["Hello", "World"],
|
|
109
|
-
* });
|
|
110
90
|
*/
|
|
111
91
|
export declare function getAI(app?: ClefbaseApp): ClefbaseAI;
|
|
112
92
|
//# sourceMappingURL=app.d.ts.map
|
package/dist/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAM9C;;;GAGG;AACH,qBAAa,WAAW;IACtB,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAEhC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,EAAS,UAAU,CAAC;IACrD,gBAAgB,CAAC,QAAQ,CAAC,SAAS,EAAO,UAAU,CAAC;IACrD,gBAAgB,CAAC,QAAQ,CAAC,YAAY,EAAI,UAAU,C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AAE,WAAW,GAAG,iBAAiB,CAEjE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,GAAG,CAAC,EAAE,WAAW,GAAG,UAAU,CAEnD"}
|
package/dist/app.js
CHANGED
|
@@ -17,6 +17,7 @@ const hosting_1 = require("./hosting");
|
|
|
17
17
|
const functions_1 = require("./functions");
|
|
18
18
|
const ai_1 = require("./ai");
|
|
19
19
|
// ─── App ──────────────────────────────────────────────────────────────────────
|
|
20
|
+
const DEFAULT_GATEWAY_URL = "https://auth.cleforyx.com";
|
|
20
21
|
/**
|
|
21
22
|
* A Clefbase application instance.
|
|
22
23
|
* Created by `initClefbase()` — pass it to `getDatabase()`, `getAuth()`, etc.
|
|
@@ -26,11 +27,10 @@ class ClefbaseApp {
|
|
|
26
27
|
this.config = config;
|
|
27
28
|
const base = config.serverUrl.replace(/\/+$/, "");
|
|
28
29
|
const cfxKey = { "x-cfx-key": config.apiKey };
|
|
29
|
-
const admin = { "x-admin-secret": config.adminSecret ?? "" };
|
|
30
30
|
this._dbHttp = new http_1.HttpClient(`${base}/db`, cfxKey);
|
|
31
31
|
this._authHttp = new http_1.HttpClient(`${base}/auth`, cfxKey);
|
|
32
32
|
this._storageHttp = new http_1.HttpClient(`${base}/storage`, cfxKey);
|
|
33
|
-
this._hostingHttp = new http_1.HttpClient(`${base}/
|
|
33
|
+
this._hostingHttp = new http_1.HttpClient(`${base}/hosting`, cfxKey);
|
|
34
34
|
this._functionsHttp = new http_1.HttpClient(`${base}/functions`, cfxKey);
|
|
35
35
|
this._aiHttp = new http_1.HttpClient(`${base}/ai`, cfxKey);
|
|
36
36
|
}
|
|
@@ -42,8 +42,9 @@ class ClefbaseApp {
|
|
|
42
42
|
}
|
|
43
43
|
/** @internal */
|
|
44
44
|
_getAuth() {
|
|
45
|
-
if (!this._auth)
|
|
46
|
-
this._auth = new auth_1.Auth(this._authHttp);
|
|
45
|
+
if (!this._auth) {
|
|
46
|
+
this._auth = new auth_1.Auth(this._authHttp, DEFAULT_GATEWAY_URL, this.config.projectId);
|
|
47
|
+
}
|
|
47
48
|
return this._auth;
|
|
48
49
|
}
|
|
49
50
|
/** @internal */
|
|
@@ -55,7 +56,7 @@ class ClefbaseApp {
|
|
|
55
56
|
/** @internal */
|
|
56
57
|
_getHosting() {
|
|
57
58
|
if (!this._hosting)
|
|
58
|
-
this._hosting = new hosting_1.ClefbaseHosting(this._hostingHttp
|
|
59
|
+
this._hosting = new hosting_1.ClefbaseHosting(this._hostingHttp);
|
|
59
60
|
return this._hosting;
|
|
60
61
|
}
|
|
61
62
|
/** @internal */
|
|
@@ -81,10 +82,10 @@ const registry = new Map();
|
|
|
81
82
|
*
|
|
82
83
|
* @example
|
|
83
84
|
* const app = initClefbase({
|
|
84
|
-
* serverUrl:
|
|
85
|
-
* projectId:
|
|
86
|
-
* apiKey:
|
|
87
|
-
*
|
|
85
|
+
* serverUrl: "https://api.cleforyx.com",
|
|
86
|
+
* projectId: "swoove-md3",
|
|
87
|
+
* apiKey: "cfx_...",
|
|
88
|
+
* // gatewayUrl defaults to "https://auth.cleforyx.com"
|
|
88
89
|
* });
|
|
89
90
|
*/
|
|
90
91
|
function initClefbase(config, name = DEFAULT) {
|
|
@@ -125,7 +126,7 @@ function getHosting(app) {
|
|
|
125
126
|
* @example
|
|
126
127
|
* import { initClefbase, getFunctions, httpsCallable } from "clefbase";
|
|
127
128
|
*
|
|
128
|
-
* const app = initClefbase({ serverUrl, projectId, apiKey
|
|
129
|
+
* const app = initClefbase({ serverUrl, projectId, apiKey });
|
|
129
130
|
* const fns = getFunctions(app);
|
|
130
131
|
*
|
|
131
132
|
* const greet = httpsCallable<{ name: string }, { message: string }>(fns, "greetUser");
|
|
@@ -140,33 +141,13 @@ function getFunctions(app) {
|
|
|
140
141
|
* @example
|
|
141
142
|
* import { initClefbase, getAI } from "clefbase";
|
|
142
143
|
*
|
|
143
|
-
* const app = initClefbase({ serverUrl, projectId, apiKey
|
|
144
|
+
* const app = initClefbase({ serverUrl, projectId, apiKey });
|
|
144
145
|
* const ai = getAI(app);
|
|
145
146
|
*
|
|
146
|
-
* // Text generation
|
|
147
147
|
* const { content } = await ai.text({
|
|
148
148
|
* model: "claude-sonnet-4-5",
|
|
149
149
|
* prompt: "Explain closures in JavaScript",
|
|
150
150
|
* });
|
|
151
|
-
*
|
|
152
|
-
* // Image generation — saved to project Storage automatically
|
|
153
|
-
* const { files } = await ai.image({
|
|
154
|
-
* model: "imagen-3.0-generate-002",
|
|
155
|
-
* prompt: "A futuristic cityscape at sunset",
|
|
156
|
-
* });
|
|
157
|
-
*
|
|
158
|
-
* // Video generation
|
|
159
|
-
* const { status, files: videoFiles } = await ai.video({
|
|
160
|
-
* model: "veo-2.0-generate-001",
|
|
161
|
-
* prompt: "A dog running on a beach",
|
|
162
|
-
* durationSeconds: 5,
|
|
163
|
-
* });
|
|
164
|
-
*
|
|
165
|
-
* // Embeddings
|
|
166
|
-
* const { embeddings } = await ai.embedding({
|
|
167
|
-
* model: "text-embedding-004",
|
|
168
|
-
* input: ["Hello", "World"],
|
|
169
|
-
* });
|
|
170
151
|
*/
|
|
171
152
|
function getAI(app) {
|
|
172
153
|
return (app ?? getApp())._getAI();
|
package/dist/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;AAmHA,oCAQC;AAGD,wBAQC;AAKD,kCAEC;AAGD,0BAEC;AAGD,gCAEC;AAGD,gCAEC;AAcD,oCAEC;AAgBD,sBAEC;AA9LD,iCAAoC;AACpC,6BAAgC;AAChC,iCAA8B;AAC9B,uCAA4C;AAC5C,uCAA4C;AAC5C,2CAAgD;AAChD,6BAAkC;AAGlC,iFAAiF;AAEjF,MAAM,mBAAmB,GAAG,2BAA2B,CAAC;AAExD;;;GAGG;AACH,MAAa,WAAW;I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";
|
|
2
2
|
import type { AuthUser, AuthResult } from "../types";
|
|
3
|
-
interface GisNotification {
|
|
4
|
-
isNotDisplayed(): boolean;
|
|
5
|
-
isSkippedMoment(): boolean;
|
|
6
|
-
isDismissedMoment(): boolean;
|
|
7
|
-
getNotDisplayedReason(): string;
|
|
8
|
-
getSkippedReason(): string;
|
|
9
|
-
getDismissedReason(): string;
|
|
10
|
-
}
|
|
11
|
-
interface GoogleAccountsId {
|
|
12
|
-
initialize(config: {
|
|
13
|
-
client_id: string;
|
|
14
|
-
callback: (response: {
|
|
15
|
-
credential: string;
|
|
16
|
-
}) => void;
|
|
17
|
-
auto_select?: boolean;
|
|
18
|
-
cancel_on_tap_outside?: boolean;
|
|
19
|
-
}): void;
|
|
20
|
-
prompt(momentListener?: (n: GisNotification) => void): void;
|
|
21
|
-
renderButton(parent: HTMLElement, options: {
|
|
22
|
-
type?: "standard" | "icon";
|
|
23
|
-
theme?: "outline" | "filled_blue" | "filled_black";
|
|
24
|
-
size?: "large" | "medium" | "small";
|
|
25
|
-
text?: "signin_with" | "signup_with" | "continue_with" | "signin";
|
|
26
|
-
shape?: "rectangular" | "pill" | "circle" | "square";
|
|
27
|
-
logo_alignment?: "left" | "center";
|
|
28
|
-
width?: number;
|
|
29
|
-
locale?: string;
|
|
30
|
-
}): void;
|
|
31
|
-
disableAutoSelect(): void;
|
|
32
|
-
revoke(hint: string, done: () => void): void;
|
|
33
|
-
}
|
|
34
|
-
declare global {
|
|
35
|
-
interface Window {
|
|
36
|
-
google?: {
|
|
37
|
-
accounts: {
|
|
38
|
-
id: GoogleAccountsId;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
3
|
/**
|
|
44
|
-
* Options for
|
|
45
|
-
* Pass to `auth.signInWithGoogle()` to show a button instead of One Tap.
|
|
4
|
+
* Options for `auth.signInWithGateway()`.
|
|
46
5
|
*/
|
|
47
|
-
export interface
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
/** Pixel width of the button (min 200, max 400). */
|
|
55
|
-
width?: number;
|
|
56
|
-
locale?: string;
|
|
6
|
+
export interface GatewaySignInOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The URL the gateway should redirect back to after authentication.
|
|
9
|
+
* Defaults to `window.location.origin` (your app's root).
|
|
10
|
+
* Must be registered as an allowed redirect for your project in the gateway.
|
|
11
|
+
*/
|
|
12
|
+
redirectUrl?: string;
|
|
57
13
|
}
|
|
58
14
|
type AuthStateCallback = (user: AuthUser | null) => void;
|
|
59
15
|
/**
|
|
@@ -61,20 +17,28 @@ type AuthStateCallback = (user: AuthUser | null) => void;
|
|
|
61
17
|
*
|
|
62
18
|
* @example
|
|
63
19
|
* const auth = getAuth(app);
|
|
20
|
+
*
|
|
21
|
+
* // Email / password
|
|
64
22
|
* const { user } = await auth.signIn("alice@example.com", "pass");
|
|
65
|
-
*
|
|
66
|
-
*
|
|
23
|
+
*
|
|
24
|
+
* // Google — redirect to gateway, come back signed in
|
|
25
|
+
* await auth.signInWithGateway("google");
|
|
26
|
+
*
|
|
27
|
+
* // On every page load, handle the gateway callback:
|
|
28
|
+
* const result = await auth.handleGatewayCallback();
|
|
29
|
+
* if (result) console.log("Signed in via gateway:", result.user.email);
|
|
67
30
|
*/
|
|
68
31
|
export declare class Auth {
|
|
69
32
|
private readonly http;
|
|
70
33
|
private readonly store;
|
|
71
34
|
private listeners;
|
|
72
|
-
/**
|
|
73
|
-
private
|
|
74
|
-
|
|
35
|
+
/** The base URL of the Cleforyx auth gateway (e.g. https://auth.cleforyx.com) */
|
|
36
|
+
private readonly gatewayUrl;
|
|
37
|
+
/** The project ID — used as the `?project=` param when redirecting to the gateway */
|
|
38
|
+
private readonly projectId;
|
|
39
|
+
constructor(http: HttpClient, gatewayUrl: string, projectId: string);
|
|
75
40
|
private notify;
|
|
76
41
|
private handleResult;
|
|
77
|
-
private resolveGoogleClientId;
|
|
78
42
|
/** @internal — used by Storage to attach the bearer token to upload requests */
|
|
79
43
|
getAuthHeaders(): Record<string, string>;
|
|
80
44
|
/** The currently signed-in user, or null. */
|
|
@@ -82,7 +46,7 @@ export declare class Auth {
|
|
|
82
46
|
/** The raw bearer token for the active session, or null. */
|
|
83
47
|
get currentToken(): string | null;
|
|
84
48
|
/**
|
|
85
|
-
* Create a new account.
|
|
49
|
+
* Create a new account with email + password.
|
|
86
50
|
*
|
|
87
51
|
* @example
|
|
88
52
|
* const { user } = await auth.signUp("alice@example.com", "pass123", {
|
|
@@ -103,75 +67,60 @@ export declare class Auth {
|
|
|
103
67
|
*/
|
|
104
68
|
signIn(email: string, password: string): Promise<AuthResult>;
|
|
105
69
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* Browser-only. The GIS script (`accounts.google.com/gsi/client`) is loaded
|
|
109
|
-
* automatically — no manual `<script>` tag needed.
|
|
70
|
+
* Redirect the user to the Cleforyx auth gateway to sign in with an
|
|
71
|
+
* OAuth provider (currently `"google"`).
|
|
110
72
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
73
|
+
* The gateway handles the OAuth flow and redirects back to your app with
|
|
74
|
+
* `?cfx_token=<token>&cfx_project=<projectId>` in the URL.
|
|
75
|
+
* Call `auth.handleGatewayCallback()` on page load to complete sign-in.
|
|
114
76
|
*
|
|
115
|
-
*
|
|
116
|
-
* seen before, a new user record is created server-side.
|
|
117
|
-
*
|
|
118
|
-
* @throws `ClefbaseError` with code `GOOGLE_NOT_CONFIGURED` if no Client ID
|
|
119
|
-
* has been set in the project's auth settings.
|
|
120
|
-
* @throws `ClefbaseError` with code `GOOGLE_PROMPT_SUPPRESSED` if One Tap
|
|
121
|
-
* could not be displayed (switch to button mode in that case).
|
|
122
|
-
* @throws `ClefbaseError` with code `GOOGLE_SIGN_IN_CANCELLED` if the user
|
|
123
|
-
* dismissed the popup.
|
|
77
|
+
* **This method never returns** — it calls `window.location.href`.
|
|
124
78
|
*
|
|
125
79
|
* @example
|
|
126
|
-
* //
|
|
127
|
-
*
|
|
80
|
+
* // On button click:
|
|
81
|
+
* await auth.signInWithGateway("google");
|
|
128
82
|
*
|
|
129
|
-
* //
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* theme: "filled_blue",
|
|
133
|
-
* size: "large",
|
|
134
|
-
* text: "continue_with",
|
|
83
|
+
* // With a custom return URL:
|
|
84
|
+
* await auth.signInWithGateway("google", {
|
|
85
|
+
* redirectUrl: "https://myapp.cleforyx.com/dashboard",
|
|
135
86
|
* });
|
|
136
|
-
*
|
|
137
|
-
* // React example
|
|
138
|
-
* const btnRef = useRef<HTMLDivElement>(null);
|
|
139
|
-
* await auth.signInWithGoogle({ container: btnRef.current! });
|
|
140
87
|
*/
|
|
141
|
-
|
|
88
|
+
signInWithGateway(provider: "google", options?: GatewaySignInOptions): Promise<never>;
|
|
142
89
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* for example with a custom button implementation, React Native Google
|
|
147
|
-
* Sign-In, or any other flow that gives you an ID token directly.
|
|
148
|
-
*
|
|
149
|
-
* Works in both browser and Node.js environments.
|
|
90
|
+
* Check if the current URL contains a gateway callback (`?cfx_token=`).
|
|
91
|
+
* Useful for rendering a "Finishing sign-in…" loading state before calling
|
|
92
|
+
* `handleGatewayCallback()`.
|
|
150
93
|
*
|
|
151
94
|
* @example
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
* callback: async ({ credential }) => {
|
|
156
|
-
* const { user } = await auth.signInWithGoogleToken(credential);
|
|
157
|
-
* },
|
|
158
|
-
* });
|
|
159
|
-
*
|
|
160
|
-
* // React Native
|
|
161
|
-
* const { idToken } = await GoogleSignin.signIn();
|
|
162
|
-
* const { user } = await auth.signInWithGoogleToken(idToken);
|
|
95
|
+
* if (auth.isGatewayCallbackPending()) {
|
|
96
|
+
* showLoadingSpinner();
|
|
97
|
+
* }
|
|
163
98
|
*/
|
|
164
|
-
|
|
99
|
+
isGatewayCallbackPending(): boolean;
|
|
165
100
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
101
|
+
* Call this on every page load (ideally before rendering your app).
|
|
102
|
+
* If the URL contains `?cfx_token=`, the token is validated against
|
|
103
|
+
* the server, the session is saved, and the signed-in `AuthResult` is
|
|
104
|
+
* returned. The query params are cleaned from the URL automatically.
|
|
105
|
+
*
|
|
106
|
+
* Returns `null` if there is no pending callback.
|
|
168
107
|
*
|
|
169
108
|
* @example
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
109
|
+
* // In your app's root component or entry point:
|
|
110
|
+
* useEffect(() => {
|
|
111
|
+
* auth.handleGatewayCallback().then(result => {
|
|
112
|
+
* if (result) {
|
|
113
|
+
* console.log("Signed in:", result.user.email);
|
|
114
|
+
* navigate("/dashboard");
|
|
115
|
+
* }
|
|
116
|
+
* });
|
|
117
|
+
* }, []);
|
|
118
|
+
*
|
|
119
|
+
* // Or outside React:
|
|
120
|
+
* const result = await auth.handleGatewayCallback();
|
|
121
|
+
* if (result) showDashboard(result.user);
|
|
173
122
|
*/
|
|
174
|
-
|
|
123
|
+
handleGatewayCallback(): Promise<AuthResult | null>;
|
|
175
124
|
/** Sign out and clear the local session. */
|
|
176
125
|
signOut(): Promise<void>;
|
|
177
126
|
/** Re-fetch the current user's profile from the server and update the cache. */
|
|
@@ -199,7 +148,7 @@ export declare class Auth {
|
|
|
199
148
|
verifyEmail(code: string): Promise<AuthUser>;
|
|
200
149
|
/**
|
|
201
150
|
* Subscribe to auth state changes.
|
|
202
|
-
* Fires immediately with the current user, then on every
|
|
151
|
+
* Fires immediately with the current user, then on every sign-in or sign-out.
|
|
203
152
|
* Returns an unsubscribe function.
|
|
204
153
|
*
|
|
205
154
|
* @example
|
package/dist/auth/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":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