@motherbase/client 1.5.0 → 1.5.1
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/admin.d.ts +131 -0
- package/dist/admin.d.ts.map +1 -0
- package/dist/admin.js +121 -0
- package/dist/admin.js.map +1 -0
- package/dist/auth.d.ts +459 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +861 -0
- package/dist/auth.js.map +1 -0
- package/dist/channel.d.ts +129 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +215 -0
- package/dist/channel.js.map +1 -0
- package/dist/compat.d.ts +40 -0
- package/dist/compat.d.ts.map +1 -0
- package/dist/compat.js +100 -0
- package/dist/compat.js.map +1 -0
- package/dist/cookie.d.ts +68 -0
- package/dist/cookie.d.ts.map +1 -0
- package/dist/cookie.js +152 -0
- package/dist/cookie.js.map +1 -0
- package/dist/database.d.ts +188 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +2 -0
- package/dist/database.js.map +1 -0
- package/dist/functions.d.ts +60 -0
- package/dist/functions.d.ts.map +1 -0
- package/dist/functions.js +75 -0
- package/dist/functions.js.map +1 -0
- package/dist/http.d.ts +122 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +206 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +215 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +365 -0
- package/dist/index.js.map +1 -0
- package/dist/mfa.d.ts +126 -0
- package/dist/mfa.d.ts.map +1 -0
- package/dist/mfa.js +156 -0
- package/dist/mfa.js.map +1 -0
- package/dist/organization.d.ts +234 -0
- package/dist/organization.d.ts.map +1 -0
- package/dist/organization.js +157 -0
- package/dist/organization.js.map +1 -0
- package/dist/passkey.d.ts +59 -0
- package/dist/passkey.d.ts.map +1 -0
- package/dist/passkey.js +87 -0
- package/dist/passkey.js.map +1 -0
- package/dist/pkce.d.ts +13 -0
- package/dist/pkce.d.ts.map +1 -0
- package/dist/pkce.js +52 -0
- package/dist/pkce.js.map +1 -0
- package/dist/plugin-endpoint.d.ts +20 -0
- package/dist/plugin-endpoint.d.ts.map +1 -0
- package/dist/plugin-endpoint.js +24 -0
- package/dist/plugin-endpoint.js.map +1 -0
- package/dist/postgrest.d.ts +326 -0
- package/dist/postgrest.d.ts.map +1 -0
- package/dist/postgrest.js +625 -0
- package/dist/postgrest.js.map +1 -0
- package/dist/query.d.ts +97 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +94 -0
- package/dist/query.js.map +1 -0
- package/dist/realtime.d.ts +114 -0
- package/dist/realtime.d.ts.map +1 -0
- package/dist/realtime.js +376 -0
- package/dist/realtime.js.map +1 -0
- package/dist/session.d.ts +47 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +136 -0
- package/dist/session.js.map +1 -0
- package/dist/sso.d.ts +147 -0
- package/dist/sso.d.ts.map +1 -0
- package/dist/sso.js +35 -0
- package/dist/sso.js.map +1 -0
- package/dist/storage.d.ts +268 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +441 -0
- package/dist/storage.js.map +1 -0
- package/dist/testing.d.ts +38 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +50 -0
- package/dist/testing.js.map +1 -0
- package/dist/types.d.ts +348 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/warn.d.ts +2 -0
- package/dist/warn.d.ts.map +1 -0
- package/dist/warn.js +23 -0
- package/dist/warn.js.map +1 -0
- package/package.json +4 -2
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import { MfaClient } from './mfa.js';
|
|
2
|
+
import { AuthAdminClient } from './admin.js';
|
|
3
|
+
import { type VerifierStore } from './pkce.js';
|
|
4
|
+
import { OrganizationClient } from './organization.js';
|
|
5
|
+
import { PasskeyClient } from './passkey.js';
|
|
6
|
+
import { SsoClient } from './sso.js';
|
|
7
|
+
import type { HttpClient } from './http.js';
|
|
8
|
+
import type { SessionStore } from './session.js';
|
|
9
|
+
import type { AuthChangeListener, MotherbaseResponse, Session, User, UserIdentity } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* The CAPTCHA response token from the hCaptcha or Turnstile widget. Required
|
|
12
|
+
* by every guarded endpoint once the project turns CAPTCHA protection on
|
|
13
|
+
* (Studio → Authentication → Attack Protection), exactly as in supabase-js.
|
|
14
|
+
*/
|
|
15
|
+
export interface CaptchaOptions {
|
|
16
|
+
captchaToken?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SignUpCredentials {
|
|
19
|
+
email: string;
|
|
20
|
+
password: string;
|
|
21
|
+
/** Optional extra profile field supported by the backend. */
|
|
22
|
+
username?: string;
|
|
23
|
+
options?: CaptchaOptions & {
|
|
24
|
+
/** Where the email-verification link sends the user. Must be an allowed redirect URL. */
|
|
25
|
+
emailRedirectTo?: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface SignInWithPasswordCredentials {
|
|
29
|
+
email: string;
|
|
30
|
+
password: string;
|
|
31
|
+
options?: CaptchaOptions;
|
|
32
|
+
}
|
|
33
|
+
export interface SignInWithOtpCredentials {
|
|
34
|
+
email?: string;
|
|
35
|
+
/** E.164 phone number. Routes to the SMS one-time code flow instead. */
|
|
36
|
+
phone?: string;
|
|
37
|
+
options?: CaptchaOptions;
|
|
38
|
+
}
|
|
39
|
+
export interface SignInAnonymouslyCredentials {
|
|
40
|
+
options?: CaptchaOptions & {
|
|
41
|
+
/** Profile fields for the guest, stored like `updateUser({ data })`. */
|
|
42
|
+
data?: Record<string, unknown>;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export interface VerifyOtpParams {
|
|
46
|
+
email?: string;
|
|
47
|
+
/** E.164 phone number, when the code was sent by SMS. */
|
|
48
|
+
phone?: string;
|
|
49
|
+
/** The code that was sent. Named `token` for supabase-js parity. */
|
|
50
|
+
token: string;
|
|
51
|
+
/**
|
|
52
|
+
* supabase-js verification type. The channel actually follows the identifier
|
|
53
|
+
* you pass; this only disambiguates if both are present. `recovery` and
|
|
54
|
+
* `email_change` are not routed: use `resetPassword` for the first, and
|
|
55
|
+
* email changes are not supported.
|
|
56
|
+
*/
|
|
57
|
+
type?: 'email' | 'sms' | 'phone_change' | 'recovery' | 'email_change' | 'signup';
|
|
58
|
+
}
|
|
59
|
+
export interface SignInWithOAuthCredentials {
|
|
60
|
+
/** Social provider id, e.g. 'google' or 'apple'. Must be enabled on the backend. */
|
|
61
|
+
provider: string;
|
|
62
|
+
options?: {
|
|
63
|
+
/** Where the provider should send the user back to after auth. */
|
|
64
|
+
redirectTo?: string;
|
|
65
|
+
/** Space-separated OAuth scopes. */
|
|
66
|
+
scopes?: string;
|
|
67
|
+
/** Skip the automatic `window.location` redirect and just return the URL. */
|
|
68
|
+
skipBrowserRedirect?: boolean;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export interface DeleteUserAttributes {
|
|
72
|
+
/** Required unless the session is already "fresh" (i.e. just re-authenticated). */
|
|
73
|
+
password?: string;
|
|
74
|
+
/** Deletion-confirmation token, when the backend's delete flow requires an email confirmation step. */
|
|
75
|
+
token?: string;
|
|
76
|
+
callbackURL?: string;
|
|
77
|
+
}
|
|
78
|
+
export interface UpdateUserAttributes {
|
|
79
|
+
/**
|
|
80
|
+
* Give an anonymous user an email address, which makes it permanent. The id
|
|
81
|
+
* does not change, so everything the guest owned stays owned. A permanent
|
|
82
|
+
* user cannot change its address through this call.
|
|
83
|
+
*/
|
|
84
|
+
email?: string;
|
|
85
|
+
/**
|
|
86
|
+
* New password. Replacing an existing one takes either `currentPassword` or
|
|
87
|
+
* the `nonce` that `reauthenticate()` emailed. A user with no password yet
|
|
88
|
+
* (a converted guest, a social sign-in) needs neither.
|
|
89
|
+
*/
|
|
90
|
+
password?: string;
|
|
91
|
+
currentPassword?: string;
|
|
92
|
+
/** The code from `reauthenticate()`. */
|
|
93
|
+
nonce?: string;
|
|
94
|
+
/** Arbitrary profile fields (name, image, or any custom additional field). */
|
|
95
|
+
data?: Record<string, unknown>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Read the token an OAuth callback left in the URL fragment and return the URL
|
|
99
|
+
* with it removed, so a reload or a shared link cannot replay it.
|
|
100
|
+
*
|
|
101
|
+
* The provider callback cannot answer the SDK with a JSON body: it is a browser
|
|
102
|
+
* redirect. The backend therefore appends `#access_token=…` to the redirect it
|
|
103
|
+
* issues, the same implicit flow supabase-js reads. Exported for testing.
|
|
104
|
+
*/
|
|
105
|
+
export declare function readAccessTokenFromUrl(href: string): {
|
|
106
|
+
accessToken: string;
|
|
107
|
+
cleanedHref: string;
|
|
108
|
+
} | null;
|
|
109
|
+
export interface Subscription {
|
|
110
|
+
unsubscribe(): void;
|
|
111
|
+
}
|
|
112
|
+
export interface AuthClientOptions {
|
|
113
|
+
/** `pkce` makes OAuth and SSO redirects come back with `?code=` for `exchangeCodeForSession`. */
|
|
114
|
+
flowType?: 'implicit' | 'pkce';
|
|
115
|
+
/** Where the PKCE verifier waits out the redirect. Defaults to localStorage, else memory. */
|
|
116
|
+
verifiers?: VerifierStore;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Supabase-compatible auth client. Maps supabase-js method names onto the
|
|
120
|
+
* Motherbase auth endpoints and reuses the existing token/refresh/session-store
|
|
121
|
+
* machinery. Returns `{ data, error }` and never throws for expected failures.
|
|
122
|
+
*/
|
|
123
|
+
export declare class AuthClient {
|
|
124
|
+
private readonly http;
|
|
125
|
+
private readonly store;
|
|
126
|
+
/**
|
|
127
|
+
* Two-factor, shaped like `supabase.auth.mfa`. The server has shipped TOTP
|
|
128
|
+
* from the start; this is the namespace that makes it reachable.
|
|
129
|
+
*/
|
|
130
|
+
readonly mfa: MfaClient;
|
|
131
|
+
/**
|
|
132
|
+
* User administration for server code holding a secret key. Present on every
|
|
133
|
+
* client, because whether the key is secret is a server-side fact: calling
|
|
134
|
+
* these with a publishable key is a 401, not a missing method.
|
|
135
|
+
*/
|
|
136
|
+
readonly admin: AuthAdminClient;
|
|
137
|
+
/**
|
|
138
|
+
* End-user organizations, members, invitations and teams. Not part of
|
|
139
|
+
* supabase-js; method names follow Better Auth's organization client.
|
|
140
|
+
*/
|
|
141
|
+
readonly organization: OrganizationClient;
|
|
142
|
+
/** The signed-in user's passkeys. Signing in with one is `signInWithPasskey`. */
|
|
143
|
+
readonly passkey: PasskeyClient;
|
|
144
|
+
/** Identity providers registered at runtime. Signing in through one is `signInWithSSO`. */
|
|
145
|
+
readonly sso: SsoClient;
|
|
146
|
+
private autoRefreshTimer;
|
|
147
|
+
private readonly flowType;
|
|
148
|
+
private readonly verifiers;
|
|
149
|
+
constructor(http: HttpClient, store: SessionStore, options?: AuthClientOptions);
|
|
150
|
+
signUp(credentials: SignUpCredentials): Promise<MotherbaseResponse<{
|
|
151
|
+
user: User | null;
|
|
152
|
+
session: Session | null;
|
|
153
|
+
}>>;
|
|
154
|
+
signInWithPassword(credentials: SignInWithPasswordCredentials): Promise<MotherbaseResponse<{
|
|
155
|
+
user: User | null;
|
|
156
|
+
session: Session | null;
|
|
157
|
+
}>>;
|
|
158
|
+
/**
|
|
159
|
+
* Sign in as a new guest, supabase-js style. The project must allow
|
|
160
|
+
* anonymous sign-ins (Studio → Authentication → Sign In / Providers).
|
|
161
|
+
*
|
|
162
|
+
* The guest is a real user whose `is_anonymous` is true, and RLS sees the
|
|
163
|
+
* same flag as the `is_anonymous` claim. Make it permanent without changing
|
|
164
|
+
* its id with `updateUser({ email })` or `linkIdentity()`.
|
|
165
|
+
*/
|
|
166
|
+
signInAnonymously(credentials?: SignInAnonymouslyCredentials): Promise<MotherbaseResponse<{
|
|
167
|
+
user: User | null;
|
|
168
|
+
session: Session | null;
|
|
169
|
+
}>>;
|
|
170
|
+
/**
|
|
171
|
+
* Email the signed-in user a one-time nonce, then pass it to
|
|
172
|
+
* `updateUser({ password, nonce })`. GoTrue's "secure password change".
|
|
173
|
+
*/
|
|
174
|
+
reauthenticate(): Promise<MotherbaseResponse<{
|
|
175
|
+
user: null;
|
|
176
|
+
session: null;
|
|
177
|
+
}>>;
|
|
178
|
+
/**
|
|
179
|
+
* Request a password-reset OTP by email. Always resolves successfully
|
|
180
|
+
* (whether or not the email is registered) to avoid leaking account
|
|
181
|
+
* existence; check `error` only for transport/server failures.
|
|
182
|
+
*/
|
|
183
|
+
resetPasswordForEmail(email: string, options?: CaptchaOptions): Promise<{
|
|
184
|
+
error: MotherbaseResponse<null>['error'];
|
|
185
|
+
}>;
|
|
186
|
+
/** Complete a password reset using the OTP sent to the user's email. */
|
|
187
|
+
resetPassword(args: {
|
|
188
|
+
email: string;
|
|
189
|
+
otp: string;
|
|
190
|
+
password: string;
|
|
191
|
+
}): Promise<{
|
|
192
|
+
error: MotherbaseResponse<null>['error'];
|
|
193
|
+
}>;
|
|
194
|
+
/**
|
|
195
|
+
* Send a one-time sign-in code, by email or by SMS. Pair with `verifyOtp` to
|
|
196
|
+
* complete the sign-in.
|
|
197
|
+
*
|
|
198
|
+
* `{ phone }` routes to the phone-number plugin, which the project has to
|
|
199
|
+
* have enabled with an SMS sender configured; without one the call resolves
|
|
200
|
+
* with the backend's error rather than pretending a code was sent.
|
|
201
|
+
*/
|
|
202
|
+
signInWithOtp(credentials: SignInWithOtpCredentials): Promise<{
|
|
203
|
+
data: Record<string, never>;
|
|
204
|
+
error: MotherbaseResponse<null>['error'];
|
|
205
|
+
}>;
|
|
206
|
+
/**
|
|
207
|
+
* Send the one-time code again, supabase-js style.
|
|
208
|
+
*
|
|
209
|
+
* supabase-js names the flows `signup` (confirm a new address), `email_change`
|
|
210
|
+
* and `recovery`; Better Auth names them `email-verification` and
|
|
211
|
+
* `forget-password`. The mapping lives here so ported code keeps working.
|
|
212
|
+
* `sms` and `phone_change` re-send an SMS code through the phone-number flow.
|
|
213
|
+
*/
|
|
214
|
+
resend(params: {
|
|
215
|
+
type: 'signup' | 'email_change' | 'recovery' | 'sms' | 'phone_change';
|
|
216
|
+
email?: string;
|
|
217
|
+
phone?: string;
|
|
218
|
+
}): Promise<{
|
|
219
|
+
data: Record<string, never>;
|
|
220
|
+
error: MotherbaseResponse<null>['error'];
|
|
221
|
+
}>;
|
|
222
|
+
/**
|
|
223
|
+
* Complete a `signInWithOtp` sign-in with the code that was sent.
|
|
224
|
+
*
|
|
225
|
+
* The channel follows the identifier, as in supabase-js: `{ phone }` verifies
|
|
226
|
+
* an SMS code, `{ email }` an email one. `type` is accepted for signature
|
|
227
|
+
* parity and only disambiguates when both are somehow present.
|
|
228
|
+
*/
|
|
229
|
+
verifyOtp(params: VerifyOtpParams): Promise<MotherbaseResponse<{
|
|
230
|
+
user: User | null;
|
|
231
|
+
session: Session | null;
|
|
232
|
+
}>>;
|
|
233
|
+
/**
|
|
234
|
+
* Start an OAuth sign-in with a configured social provider. Resolves with the
|
|
235
|
+
* provider's authorize URL and, in a browser, redirects to it immediately
|
|
236
|
+
* unless `options.skipBrowserRedirect` is set.
|
|
237
|
+
*/
|
|
238
|
+
signInWithOAuth(credentials: SignInWithOAuthCredentials): Promise<MotherbaseResponse<{
|
|
239
|
+
provider: string;
|
|
240
|
+
url: string | null;
|
|
241
|
+
}>>;
|
|
242
|
+
/**
|
|
243
|
+
* Sign in with a passkey saved on this device or a synced one. Opens the
|
|
244
|
+
* browser's passkey prompt; dismissing it resolves with an error, not a throw.
|
|
245
|
+
* Needs Auth · Passkey on and a browser (see `auth.passkey`).
|
|
246
|
+
*/
|
|
247
|
+
signInWithPasskey(): Promise<MotherbaseResponse<{
|
|
248
|
+
user: User | null;
|
|
249
|
+
session: Session | null;
|
|
250
|
+
}>>;
|
|
251
|
+
/**
|
|
252
|
+
* Start an enterprise SSO sign-in. Identify the provider by the user's email
|
|
253
|
+
* domain, by an explicit `domain`, or by `providerId` when you already know
|
|
254
|
+
* which one to use.
|
|
255
|
+
*
|
|
256
|
+
* Resolves with the identity provider's URL and, in a browser, redirects to it
|
|
257
|
+
* unless `options.skipBrowserRedirect` is set. The project must have the SSO
|
|
258
|
+
* plugin enabled and at least one provider registered (Studio →
|
|
259
|
+
* Authentication → Organizations & SSO).
|
|
260
|
+
*/
|
|
261
|
+
signInWithSSO(params: {
|
|
262
|
+
domain?: string;
|
|
263
|
+
email?: string;
|
|
264
|
+
providerId?: string;
|
|
265
|
+
organizationSlug?: string;
|
|
266
|
+
options?: {
|
|
267
|
+
redirectTo?: string;
|
|
268
|
+
skipBrowserRedirect?: boolean;
|
|
269
|
+
};
|
|
270
|
+
}): Promise<MotherbaseResponse<{
|
|
271
|
+
url: string | null;
|
|
272
|
+
}>>;
|
|
273
|
+
/**
|
|
274
|
+
* Update the signed-in user's profile fields and/or password. Password
|
|
275
|
+
* changes require `currentPassword` (a Better Auth requirement. There is no
|
|
276
|
+
* blind password overwrite from an authenticated session).
|
|
277
|
+
*/
|
|
278
|
+
updateUser(attributes: UpdateUserAttributes): Promise<MotherbaseResponse<{
|
|
279
|
+
user: User | null;
|
|
280
|
+
}>>;
|
|
281
|
+
/**
|
|
282
|
+
* Permanently delete the signed-in user's account. Not part of the
|
|
283
|
+
* supabase-js client surface (there it's admin-only). Kept here because
|
|
284
|
+
* self-service account deletion is a real product need. Requires the
|
|
285
|
+
* backend's `delete-user` flow to be enabled; clears the local session on
|
|
286
|
+
* success.
|
|
287
|
+
*/
|
|
288
|
+
deleteUser(attributes?: DeleteUserAttributes): Promise<{
|
|
289
|
+
error: MotherbaseResponse<null>['error'];
|
|
290
|
+
}>;
|
|
291
|
+
/**
|
|
292
|
+
* Adopt an externally-obtained access token as the current session (e.g. one
|
|
293
|
+
* captured from an OAuth redirect). Validates it against the server before
|
|
294
|
+
* persisting. `refresh_token` is accepted for supabase-js signature parity
|
|
295
|
+
* and unused: Better Auth bearer sessions have none.
|
|
296
|
+
*/
|
|
297
|
+
setSession(currentSession: {
|
|
298
|
+
access_token: string;
|
|
299
|
+
refresh_token?: string;
|
|
300
|
+
}): Promise<MotherbaseResponse<{
|
|
301
|
+
user: User | null;
|
|
302
|
+
session: Session | null;
|
|
303
|
+
}>>;
|
|
304
|
+
signOut(): Promise<{
|
|
305
|
+
error: MotherbaseResponse<null>['error'];
|
|
306
|
+
}>;
|
|
307
|
+
/**
|
|
308
|
+
* Finish an OAuth / SSO sign-in after the provider redirected back.
|
|
309
|
+
*
|
|
310
|
+
* `signInWithOAuth` only starts the flow; the session is created during the
|
|
311
|
+
* redirect the browser makes to the backend callback, so the SDK has to pick
|
|
312
|
+
* it up from the URL the browser landed on. Call this once on the page you
|
|
313
|
+
* pointed `redirectTo` at (or on app start, which is where supabase-js does
|
|
314
|
+
* the equivalent). Without it the user is signed in on the backend and signed
|
|
315
|
+
* out in your app.
|
|
316
|
+
*
|
|
317
|
+
* Resolves with a null session and no error when there is nothing to read, so
|
|
318
|
+
* it is safe to call on every page load.
|
|
319
|
+
*/
|
|
320
|
+
getSessionFromUrl(href?: string): Promise<MotherbaseResponse<{
|
|
321
|
+
user: User | null;
|
|
322
|
+
session: Session | null;
|
|
323
|
+
}>>;
|
|
324
|
+
/**
|
|
325
|
+
* Finish a PKCE sign-in: trade the `?code=` the provider redirect came back
|
|
326
|
+
* with for the session. Needs the verifier `signInWithOAuth` stored, so it
|
|
327
|
+
* works once, in the browser that started the flow.
|
|
328
|
+
*/
|
|
329
|
+
exchangeCodeForSession(authCode: string): Promise<MotherbaseResponse<{
|
|
330
|
+
user: User | null;
|
|
331
|
+
session: Session | null;
|
|
332
|
+
}>>;
|
|
333
|
+
/**
|
|
334
|
+
* The redirect a flow should use. Implicit: as given. PKCE: with a fresh
|
|
335
|
+
* challenge on it, the verifier stored for `exchangeCodeForSession`; the
|
|
336
|
+
* challenge rides on the redirect URL, so PKCE needs one, and in a browser
|
|
337
|
+
* the current page stands in when none is given.
|
|
338
|
+
*/
|
|
339
|
+
private redirectForFlow;
|
|
340
|
+
/** Fetch the current user from Better Auth (requires a valid session). */
|
|
341
|
+
getUser(): Promise<MotherbaseResponse<{
|
|
342
|
+
user: User | null;
|
|
343
|
+
}>>;
|
|
344
|
+
/**
|
|
345
|
+
* NEVER USE FOR AN AUTHORIZATION DECISION. Use {@link getUser} instead.
|
|
346
|
+
*
|
|
347
|
+
* The locally-held session, if any (no network call). It is whatever the
|
|
348
|
+
* caller's cookie or storage said, parsed: unsigned JSON the browser sent,
|
|
349
|
+
* which anyone can set by hand. `session.user.id`, `.email` and `.role` are
|
|
350
|
+
* therefore attacker-controlled, and an admin allowlist checked against
|
|
351
|
+
* them is checked against nothing.
|
|
352
|
+
*
|
|
353
|
+
* Reads and writes through `from()` are unaffected: they carry the access
|
|
354
|
+
* token to the backend, which verifies it under RLS. It is the decisions
|
|
355
|
+
* your own app takes from `session.user` that are forgeable.
|
|
356
|
+
*
|
|
357
|
+
* `getUser()` costs one round trip and returns the user the backend
|
|
358
|
+
* confirms, in the same `{ data, error }` shape. Prefer it everywhere but a
|
|
359
|
+
* cosmetic "am I probably signed in" check.
|
|
360
|
+
*/
|
|
361
|
+
getSession(): Promise<MotherbaseResponse<{
|
|
362
|
+
session: Session | null;
|
|
363
|
+
}>>;
|
|
364
|
+
/**
|
|
365
|
+
* Revalidate the current session against the server. Better Auth bearer
|
|
366
|
+
* sessions have no refresh token: if the session is still valid the user is
|
|
367
|
+
* refreshed; otherwise the local session is cleared.
|
|
368
|
+
*/
|
|
369
|
+
refreshSession(): Promise<MotherbaseResponse<{
|
|
370
|
+
user: User | null;
|
|
371
|
+
session: Session | null;
|
|
372
|
+
}>>;
|
|
373
|
+
/**
|
|
374
|
+
* Subscribe to auth changes, supabase-js style.
|
|
375
|
+
*
|
|
376
|
+
* The callback fires once with `INITIAL_SESSION` as soon as the stored
|
|
377
|
+
* session has been read, before any later event. That first call is not a
|
|
378
|
+
* nicety: the standard Supabase bootstrap is
|
|
379
|
+
* `if (event === 'INITIAL_SESSION') setLoading(false)`, and without it the
|
|
380
|
+
* app renders its loading state forever for a signed-out visitor, who never
|
|
381
|
+
* produces any other event.
|
|
382
|
+
*
|
|
383
|
+
* It is delivered asynchronously (after hydration), so unsubscribing
|
|
384
|
+
* synchronously suppresses it, exactly as in supabase-js.
|
|
385
|
+
*/
|
|
386
|
+
/**
|
|
387
|
+
* The providers linked to the signed-in user, in the supabase-js identity
|
|
388
|
+
* shape. Backed by Better Auth's `list-accounts`, which is why `email` shows
|
|
389
|
+
* up as an identity for a password account: it is a real linked credential,
|
|
390
|
+
* exactly as in Supabase.
|
|
391
|
+
*/
|
|
392
|
+
getUserIdentities(): Promise<MotherbaseResponse<{
|
|
393
|
+
identities: UserIdentity[];
|
|
394
|
+
}>>;
|
|
395
|
+
/**
|
|
396
|
+
* Link another provider to the signed-in user. Like `signInWithOAuth`, this
|
|
397
|
+
* only starts the flow: the browser is sent to the provider and comes back
|
|
398
|
+
* through the callback.
|
|
399
|
+
*/
|
|
400
|
+
linkIdentity(credentials: SignInWithOAuthCredentials): Promise<MotherbaseResponse<{
|
|
401
|
+
provider: string;
|
|
402
|
+
url: string | null;
|
|
403
|
+
}>>;
|
|
404
|
+
/** Unlink a provider from the signed-in user. */
|
|
405
|
+
unlinkIdentity(identity: {
|
|
406
|
+
provider: string;
|
|
407
|
+
id?: string;
|
|
408
|
+
identity_id?: string;
|
|
409
|
+
}): Promise<MotherbaseResponse<Record<string, never>>>;
|
|
410
|
+
/**
|
|
411
|
+
* Native mobile sign-in with a provider id token (Sign in with Apple, Google
|
|
412
|
+
* One Tap), routed to Better Auth's social sign-in with an `idToken`.
|
|
413
|
+
* The provider must be configured on the backend.
|
|
414
|
+
*/
|
|
415
|
+
signInWithIdToken(params: {
|
|
416
|
+
provider: string;
|
|
417
|
+
token: string;
|
|
418
|
+
access_token?: string;
|
|
419
|
+
nonce?: string;
|
|
420
|
+
}): Promise<MotherbaseResponse<{
|
|
421
|
+
user: User | null;
|
|
422
|
+
session: Session | null;
|
|
423
|
+
}>>;
|
|
424
|
+
/**
|
|
425
|
+
* Claims for the current session, as a JWT payload.
|
|
426
|
+
*
|
|
427
|
+
* supabase-js reads them out of the access token, which is itself a JWT.
|
|
428
|
+
* A Better Auth session token is an opaque bearer, so this asks the server's
|
|
429
|
+
* jwt plugin to mint one and decodes it. The decode is NOT a verification:
|
|
430
|
+
* the token came from the authenticated endpoint over TLS, and a client
|
|
431
|
+
* verifying a token it just asked for proves nothing. Verify server side,
|
|
432
|
+
* against `/api/auth/jwks`.
|
|
433
|
+
*/
|
|
434
|
+
getClaims(): Promise<MotherbaseResponse<{
|
|
435
|
+
claims: Record<string, unknown>;
|
|
436
|
+
token: string;
|
|
437
|
+
}>>;
|
|
438
|
+
/**
|
|
439
|
+
* Revalidate the session on a timer, the way supabase-js does while the tab
|
|
440
|
+
* is focused. Motherbase refreshes on a 401 already, so this is opt-in: it
|
|
441
|
+
* exists so a ported app that calls it keeps working, and so a long-lived
|
|
442
|
+
* screen notices a revoked session without waiting for its next request.
|
|
443
|
+
*/
|
|
444
|
+
startAutoRefresh(intervalMs?: number): void;
|
|
445
|
+
/** Stop the timer started by `startAutoRefresh`. Safe to call when none runs. */
|
|
446
|
+
stopAutoRefresh(): void;
|
|
447
|
+
onAuthStateChange(callback: AuthChangeListener): {
|
|
448
|
+
data: {
|
|
449
|
+
subscription: Subscription;
|
|
450
|
+
};
|
|
451
|
+
};
|
|
452
|
+
/**
|
|
453
|
+
* Internal: refresh used by the HttpClient's 401 path. Returns true on success.
|
|
454
|
+
* Not part of the public Supabase surface.
|
|
455
|
+
*/
|
|
456
|
+
_refresh(): Promise<boolean>;
|
|
457
|
+
private persist;
|
|
458
|
+
}
|
|
459
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAA4E,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;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