@motherbase/client 1.2.8 → 1.4.0
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/README.md +73 -9
- package/dist/auth.d.ts +172 -14
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +399 -14
- package/dist/auth.js.map +1 -1
- package/dist/channel.d.ts +15 -12
- package/dist/channel.d.ts.map +1 -1
- package/dist/channel.js.map +1 -1
- package/dist/compat.d.ts +40 -0
- package/dist/compat.d.ts.map +1 -0
- package/dist/compat.js +98 -0
- package/dist/compat.js.map +1 -0
- package/dist/cookie.d.ts +23 -2
- package/dist/cookie.d.ts.map +1 -1
- package/dist/cookie.js +71 -9
- package/dist/cookie.js.map +1 -1
- package/dist/database.d.ts +20 -1
- package/dist/database.d.ts.map +1 -1
- package/dist/functions.d.ts +36 -0
- package/dist/functions.d.ts.map +1 -1
- package/dist/functions.js +56 -5
- package/dist/functions.js.map +1 -1
- package/dist/http.d.ts +47 -7
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +73 -12
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +79 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +183 -11
- package/dist/index.js.map +1 -1
- package/dist/postgrest.d.ts +94 -1
- package/dist/postgrest.d.ts.map +1 -1
- package/dist/postgrest.js +185 -17
- package/dist/postgrest.js.map +1 -1
- 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/session.d.ts +19 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +57 -4
- package/dist/session.js.map +1 -1
- package/dist/storage.d.ts +172 -5
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +249 -6
- package/dist/storage.js.map +1 -1
- 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 +264 -20
- package/dist/types.d.ts.map +1 -1
- package/dist/warn.d.ts +4 -0
- package/dist/warn.d.ts.map +1 -0
- package/dist/warn.js +27 -0
- package/dist/warn.js.map +1 -0
- package/package.json +60 -52
package/README.md
CHANGED
|
@@ -10,14 +10,17 @@ import and the client factory, keep your queries. Every `supabase-js` data call
|
|
|
10
10
|
in the contract suite is either supported or supported with a stated difference,
|
|
11
11
|
including relational embedding (`select('*, author(*)')`), `.rpc()`, native
|
|
12
12
|
`upsert`, `count`, `csv()`, the full filter set and PostgREST error codes.
|
|
13
|
-
Auth and realtime are close, with named gaps (no PKCE code exchange, no
|
|
14
|
-
|
|
13
|
+
Auth and realtime are close, with named gaps (no PKCE code exchange, no
|
|
14
|
+
`generateLink`, no private channels). Two-factor (`client.auth.mfa.*`), SSO,
|
|
15
|
+
linked identities and secret-key user administration (`client.auth.admin.*`) are
|
|
16
|
+
all here.
|
|
15
17
|
|
|
16
18
|
**Storage is path-addressed too**: `upload('avatars/123/pic.png')` then
|
|
17
19
|
`download('avatars/123/pic.png')` round trips, `list(prefix)` works, and keys are
|
|
18
|
-
traversal-checked.
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
traversal-checked. `copy`, `move`, `info`, `exists`, batch signed URLs and
|
|
21
|
+
direct-to-storage signed uploads are supported; image transforms are not.
|
|
22
|
+
Authorization is ownership plus bucket tokens by default, and real RLS policies on
|
|
23
|
+
`storage.files` when the `storage.policies` setting is on. See
|
|
21
24
|
[`docs/migrating-from-supabase.md`](../../docs/migrating-from-supabase.md).
|
|
22
25
|
|
|
23
26
|
Do not plan a migration from the paragraph above. Plan it from
|
|
@@ -107,7 +110,8 @@ client.from(table).select(cols).limit(n, { referencedTable }).range(from, to).ab
|
|
|
107
110
|
client.from(table).select(cols).or('a.eq.1,and(b.gt.2,c.is.null)') // nests, as PostgREST does
|
|
108
111
|
client.from(table).select(cols).not(col, 'eq', v).filter(col, 'isdistinct', v)
|
|
109
112
|
client.from(table).select(cols).textSearch(col, q, { type: 'websearch', config: 'english' })
|
|
110
|
-
client.from(table).select(cols).single() | .maybeSingle() | .returns<T>() | .csv() | .explain()
|
|
113
|
+
client.from(table).select(cols).single() | .maybeSingle() | .returns<T>() | .csv() | .geojson() | .explain()
|
|
114
|
+
client.from(table).update(v).eq(..).throwOnError() | .maxAffected(1) | .rollback()
|
|
111
115
|
client.from(table).insert(row) | .insert([rowA, rowB], { defaultToNull: false })
|
|
112
116
|
client.from(table).upsert(rows, { onConflict, ignoreDuplicates })
|
|
113
117
|
client.from(table).update(values).eq(..) // a filter is required
|
|
@@ -136,6 +140,7 @@ client.auth.signInWithPassword({ email, password })
|
|
|
136
140
|
client.auth.signInWithOtp({ email }) // emails a code
|
|
137
141
|
client.auth.verifyOtp({ email, token }) // completes the OTP sign-in
|
|
138
142
|
client.auth.signInWithOAuth({ provider, options: { redirectTo, scopes, skipBrowserRedirect } })
|
|
143
|
+
client.auth.getSessionFromUrl() // finishes the OAuth redirect, see below
|
|
139
144
|
client.auth.resetPasswordForEmail(email)
|
|
140
145
|
client.auth.resetPassword({ email, otp, password })
|
|
141
146
|
client.auth.updateUser({ data, password, currentPassword })
|
|
@@ -146,6 +151,14 @@ client.auth.getSession() // { data: { session } }, local only
|
|
|
146
151
|
client.auth.refreshSession()
|
|
147
152
|
client.auth.onAuthStateChange((event, session) => {}) // SIGNED_IN | SIGNED_OUT | TOKEN_REFRESHED
|
|
148
153
|
client.auth.deleteUser({ password }) // self-service, needs the backend flow enabled
|
|
154
|
+
client.auth.signInWithSSO({ domain | providerId | email })
|
|
155
|
+
client.auth.signInWithIdToken({ provider, token, nonce }) // Apple / Google One Tap
|
|
156
|
+
client.auth.getUserIdentities() | .linkIdentity({ provider }) | .unlinkIdentity({ provider, id })
|
|
157
|
+
client.auth.getClaims() // { claims, token }, decoded from a minted JWT
|
|
158
|
+
client.auth.startAutoRefresh(ms) | .stopAutoRefresh()
|
|
159
|
+
client.auth.mfa.enroll({ password }) | .challenge({ channel }) | .verify({ code, type? })
|
|
160
|
+
client.auth.mfa.listFactors() | .regenerateBackupCodes({ password }) | .unenroll({ password })
|
|
161
|
+
client.auth.admin.* // secret key only: list/get/create/update/delete/signOut/invite
|
|
149
162
|
|
|
150
163
|
// Storage → { data, error }. `path` is the object key inside the bucket, and it
|
|
151
164
|
// round trips. The file id returned by upload still works anywhere a path does.
|
|
@@ -153,8 +166,14 @@ client.storage.from(bucket).upload(path, file, { visibility, upsert })
|
|
|
153
166
|
client.storage.from(bucket).download(path)
|
|
154
167
|
client.storage.from(bucket).remove([path])
|
|
155
168
|
client.storage.from(bucket).list(prefix, { limit, offset, search, sortBy })
|
|
156
|
-
client.storage.from(bucket).createSignedUrl(path, expiresIn) //
|
|
169
|
+
client.storage.from(bucket).createSignedUrl(path, expiresIn) // seconds, 1..604800
|
|
170
|
+
client.storage.from(bucket).createSignedUrls([path], expiresIn) // per-entry results
|
|
157
171
|
client.storage.from(bucket).getPublicUrl(path) // sync
|
|
172
|
+
client.storage.from(bucket).update(path, file) // upload with upsert on
|
|
173
|
+
client.storage.from(bucket).copy(from, to, { upsert }) | .move(from, to, { upsert })
|
|
174
|
+
client.storage.from(bucket).info(path) | .exists(path) // 404 reads as false
|
|
175
|
+
client.storage.from(bucket).createSignedUploadUrl(path, { size, contentType }) // S3 driver
|
|
176
|
+
client.storage.from(bucket).uploadToSignedUrl(path, token, file)
|
|
158
177
|
|
|
159
178
|
// Realtime
|
|
160
179
|
client.channel(name, { config: { broadcast: { self, ack }, presence: { key } } })
|
|
@@ -166,10 +185,55 @@ channel.send({ type: 'broadcast', event, payload })
|
|
|
166
185
|
channel.track(state); channel.untrack(); channel.presenceState()
|
|
167
186
|
client.removeChannel(channel)
|
|
168
187
|
|
|
169
|
-
// Edge functions → { data, error }
|
|
170
|
-
|
|
188
|
+
// Edge functions → { data, error }. `error` is a FunctionsHttpError /
|
|
189
|
+
// FunctionsFetchError instance, but invoke still resolves rather than throws.
|
|
190
|
+
client.functions.invoke(name, { body, method, headers, auth })
|
|
171
191
|
```
|
|
172
192
|
|
|
193
|
+
## Social sign-in (OAuth)
|
|
194
|
+
|
|
195
|
+
A provider callback is a browser redirect, so it cannot answer the SDK with a
|
|
196
|
+
session the way a password sign-in does. Two calls, not one:
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
// 1. Wherever the button lives. Navigates the browser to the backend, which
|
|
200
|
+
// redirects on to the provider.
|
|
201
|
+
await client.auth.signInWithOAuth({
|
|
202
|
+
provider: 'google',
|
|
203
|
+
options: { redirectTo: 'https://app.example.com/auth/callback' },
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// 2. On that page (or on app start). Reads the token the backend appended to
|
|
207
|
+
// the redirect, stores the session, and strips it from the address bar.
|
|
208
|
+
const { data, error } = await client.auth.getSessionFromUrl();
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
`getSessionFromUrl()` resolves with a null session and no error when there is
|
|
212
|
+
nothing to read, so calling it on every page load is safe.
|
|
213
|
+
|
|
214
|
+
Step 1 is a full-page navigation, not a fetch. That is deliberate: the backend
|
|
215
|
+
sets an OAuth state cookie there and re-checks it on the provider callback, and
|
|
216
|
+
a cookie set on a cross-site fetch response is refused by Safari and Firefox and
|
|
217
|
+
by Chrome in incognito. Navigating makes it a first-party cookie, so the flow
|
|
218
|
+
works in every browser even when your app and your API are on different domains.
|
|
219
|
+
If you are not using the SDK, point the button at the same URL:
|
|
220
|
+
|
|
221
|
+
```
|
|
222
|
+
https://<your-api>/api/auth/sign-in/social/google?callbackURL=https://app.example.com/auth/callback
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
`callbackURL` is validated against the trusted origins, so it has to be an
|
|
226
|
+
origin you allowlisted.
|
|
227
|
+
|
|
228
|
+
Two backend settings decide whether this works at all:
|
|
229
|
+
|
|
230
|
+
- **Callback URL.** Studio, Authentication, Sign In / Providers shows the exact
|
|
231
|
+
URL to register in the provider's console.
|
|
232
|
+
- **CORS allowed origins.** Studio, Authentication settings, Security · CORS.
|
|
233
|
+
If your app is served from a different origin than the API, that origin must
|
|
234
|
+
be listed. Otherwise the browser refuses the cookie the sign-in start sets,
|
|
235
|
+
and the provider callback comes back as `?error=state_mismatch`.
|
|
236
|
+
|
|
173
237
|
## Storage adapters
|
|
174
238
|
|
|
175
239
|
| Runtime | Adapter |
|
package/dist/auth.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { MfaClient } from './mfa.js';
|
|
|
2
2
|
import { AuthAdminClient } from './admin.js';
|
|
3
3
|
import type { HttpClient } from './http.js';
|
|
4
4
|
import type { SessionStore } from './session.js';
|
|
5
|
-
import type { AuthChangeListener, MotherbaseResponse, Session, User } from './types.js';
|
|
5
|
+
import type { AuthChangeListener, MotherbaseResponse, Session, User, UserIdentity } from './types.js';
|
|
6
6
|
export interface SignUpCredentials {
|
|
7
7
|
email: string;
|
|
8
8
|
password: string;
|
|
@@ -14,14 +14,23 @@ export interface SignInWithPasswordCredentials {
|
|
|
14
14
|
password: string;
|
|
15
15
|
}
|
|
16
16
|
export interface SignInWithOtpCredentials {
|
|
17
|
-
email
|
|
17
|
+
email?: string;
|
|
18
|
+
/** E.164 phone number. Routes to the SMS one-time code flow instead. */
|
|
19
|
+
phone?: string;
|
|
18
20
|
}
|
|
19
21
|
export interface VerifyOtpParams {
|
|
20
|
-
email
|
|
21
|
-
/**
|
|
22
|
+
email?: string;
|
|
23
|
+
/** E.164 phone number, when the code was sent by SMS. */
|
|
24
|
+
phone?: string;
|
|
25
|
+
/** The code that was sent. Named `token` for supabase-js parity. */
|
|
22
26
|
token: string;
|
|
23
|
-
/**
|
|
24
|
-
|
|
27
|
+
/**
|
|
28
|
+
* supabase-js verification type. The channel actually follows the identifier
|
|
29
|
+
* you pass; this only disambiguates if both are present. `recovery` and
|
|
30
|
+
* `email_change` are not routed: use `resetPassword` for the first, and
|
|
31
|
+
* email changes are not supported.
|
|
32
|
+
*/
|
|
33
|
+
type?: 'email' | 'sms' | 'phone_change' | 'recovery' | 'email_change' | 'signup';
|
|
25
34
|
}
|
|
26
35
|
export interface SignInWithOAuthCredentials {
|
|
27
36
|
/** Social provider id, e.g. 'google' or 'apple'. Must be enabled on the backend. */
|
|
@@ -43,13 +52,25 @@ export interface DeleteUserAttributes {
|
|
|
43
52
|
callbackURL?: string;
|
|
44
53
|
}
|
|
45
54
|
export interface UpdateUserAttributes {
|
|
46
|
-
/** New password. Requires `currentPassword
|
|
55
|
+
/** New password. Requires `currentPassword`. The backend does not allow a
|
|
47
56
|
* blind password change from an authenticated session. */
|
|
48
57
|
password?: string;
|
|
49
58
|
currentPassword?: string;
|
|
50
59
|
/** Arbitrary profile fields (name, image, or any custom additional field). */
|
|
51
60
|
data?: Record<string, unknown>;
|
|
52
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Read the token an OAuth callback left in the URL fragment and return the URL
|
|
64
|
+
* with it removed, so a reload or a shared link cannot replay it.
|
|
65
|
+
*
|
|
66
|
+
* The provider callback cannot answer the SDK with a JSON body: it is a browser
|
|
67
|
+
* redirect. The backend therefore appends `#access_token=…` to the redirect it
|
|
68
|
+
* issues, the same implicit flow supabase-js reads. Exported for testing.
|
|
69
|
+
*/
|
|
70
|
+
export declare function readAccessTokenFromUrl(href: string): {
|
|
71
|
+
accessToken: string;
|
|
72
|
+
cleanedHref: string;
|
|
73
|
+
} | null;
|
|
53
74
|
export interface Subscription {
|
|
54
75
|
unsubscribe(): void;
|
|
55
76
|
}
|
|
@@ -72,6 +93,7 @@ export declare class AuthClient {
|
|
|
72
93
|
* these with a publishable key is a 401, not a missing method.
|
|
73
94
|
*/
|
|
74
95
|
readonly admin: AuthAdminClient;
|
|
96
|
+
private autoRefreshTimer;
|
|
75
97
|
constructor(http: HttpClient, store: SessionStore);
|
|
76
98
|
signUp(credentials: SignUpCredentials): Promise<MotherbaseResponse<{
|
|
77
99
|
user: User | null;
|
|
@@ -97,12 +119,41 @@ export declare class AuthClient {
|
|
|
97
119
|
}): Promise<{
|
|
98
120
|
error: MotherbaseResponse<null>['error'];
|
|
99
121
|
}>;
|
|
100
|
-
/**
|
|
122
|
+
/**
|
|
123
|
+
* Send a one-time sign-in code, by email or by SMS. Pair with `verifyOtp` to
|
|
124
|
+
* complete the sign-in.
|
|
125
|
+
*
|
|
126
|
+
* `{ phone }` routes to the phone-number plugin, which the project has to
|
|
127
|
+
* have enabled with an SMS sender configured; without one the call resolves
|
|
128
|
+
* with the backend's error rather than pretending a code was sent.
|
|
129
|
+
*/
|
|
101
130
|
signInWithOtp(credentials: SignInWithOtpCredentials): Promise<{
|
|
102
131
|
data: Record<string, never>;
|
|
103
132
|
error: MotherbaseResponse<null>['error'];
|
|
104
133
|
}>;
|
|
105
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* Send the one-time code again, supabase-js style.
|
|
136
|
+
*
|
|
137
|
+
* supabase-js names the flows `signup` (confirm a new address), `email_change`
|
|
138
|
+
* and `recovery`; Better Auth names them `email-verification` and
|
|
139
|
+
* `forget-password`. The mapping lives here so ported code keeps working.
|
|
140
|
+
* `sms` and `phone_change` re-send an SMS code through the phone-number flow.
|
|
141
|
+
*/
|
|
142
|
+
resend(params: {
|
|
143
|
+
type: 'signup' | 'email_change' | 'recovery' | 'sms' | 'phone_change';
|
|
144
|
+
email?: string;
|
|
145
|
+
phone?: string;
|
|
146
|
+
}): Promise<{
|
|
147
|
+
data: Record<string, never>;
|
|
148
|
+
error: MotherbaseResponse<null>['error'];
|
|
149
|
+
}>;
|
|
150
|
+
/**
|
|
151
|
+
* Complete a `signInWithOtp` sign-in with the code that was sent.
|
|
152
|
+
*
|
|
153
|
+
* The channel follows the identifier, as in supabase-js: `{ phone }` verifies
|
|
154
|
+
* an SMS code, `{ email }` an email one. `type` is accepted for signature
|
|
155
|
+
* parity and only disambiguates when both are somehow present.
|
|
156
|
+
*/
|
|
106
157
|
verifyOtp(params: VerifyOtpParams): Promise<MotherbaseResponse<{
|
|
107
158
|
user: User | null;
|
|
108
159
|
session: Session | null;
|
|
@@ -140,7 +191,7 @@ export declare class AuthClient {
|
|
|
140
191
|
}>>;
|
|
141
192
|
/**
|
|
142
193
|
* Update the signed-in user's profile fields and/or password. Password
|
|
143
|
-
* changes require `currentPassword` (a Better Auth requirement
|
|
194
|
+
* changes require `currentPassword` (a Better Auth requirement. There is no
|
|
144
195
|
* blind password overwrite from an authenticated session).
|
|
145
196
|
*/
|
|
146
197
|
updateUser(attributes: UpdateUserAttributes): Promise<MotherbaseResponse<{
|
|
@@ -148,7 +199,7 @@ export declare class AuthClient {
|
|
|
148
199
|
}>>;
|
|
149
200
|
/**
|
|
150
201
|
* Permanently delete the signed-in user's account. Not part of the
|
|
151
|
-
* supabase-js client surface (there it's admin-only)
|
|
202
|
+
* supabase-js client surface (there it's admin-only). Kept here because
|
|
152
203
|
* self-service account deletion is a real product need. Requires the
|
|
153
204
|
* backend's `delete-user` flow to be enabled; clears the local session on
|
|
154
205
|
* success.
|
|
@@ -160,7 +211,7 @@ export declare class AuthClient {
|
|
|
160
211
|
* Adopt an externally-obtained access token as the current session (e.g. one
|
|
161
212
|
* captured from an OAuth redirect). Validates it against the server before
|
|
162
213
|
* persisting. `refresh_token` is accepted for supabase-js signature parity
|
|
163
|
-
* and unused
|
|
214
|
+
* and unused: Better Auth bearer sessions have none.
|
|
164
215
|
*/
|
|
165
216
|
setSession(currentSession: {
|
|
166
217
|
access_token: string;
|
|
@@ -172,23 +223,130 @@ export declare class AuthClient {
|
|
|
172
223
|
signOut(): Promise<{
|
|
173
224
|
error: MotherbaseResponse<null>['error'];
|
|
174
225
|
}>;
|
|
226
|
+
/**
|
|
227
|
+
* Finish an OAuth / SSO sign-in after the provider redirected back.
|
|
228
|
+
*
|
|
229
|
+
* `signInWithOAuth` only starts the flow; the session is created during the
|
|
230
|
+
* redirect the browser makes to the backend callback, so the SDK has to pick
|
|
231
|
+
* it up from the URL the browser landed on. Call this once on the page you
|
|
232
|
+
* pointed `redirectTo` at (or on app start, which is where supabase-js does
|
|
233
|
+
* the equivalent). Without it the user is signed in on the backend and signed
|
|
234
|
+
* out in your app.
|
|
235
|
+
*
|
|
236
|
+
* Resolves with a null session and no error when there is nothing to read, so
|
|
237
|
+
* it is safe to call on every page load.
|
|
238
|
+
*/
|
|
239
|
+
getSessionFromUrl(href?: string): Promise<MotherbaseResponse<{
|
|
240
|
+
user: User | null;
|
|
241
|
+
session: Session | null;
|
|
242
|
+
}>>;
|
|
175
243
|
/** Fetch the current user from Better Auth (requires a valid session). */
|
|
176
244
|
getUser(): Promise<MotherbaseResponse<{
|
|
177
245
|
user: User | null;
|
|
178
246
|
}>>;
|
|
179
|
-
/**
|
|
247
|
+
/**
|
|
248
|
+
* NEVER USE FOR AN AUTHORIZATION DECISION. Use {@link getUser} instead.
|
|
249
|
+
*
|
|
250
|
+
* The locally-held session, if any (no network call). It is whatever the
|
|
251
|
+
* caller's cookie or storage said, parsed: unsigned JSON the browser sent,
|
|
252
|
+
* which anyone can set by hand. `session.user.id`, `.email` and `.role` are
|
|
253
|
+
* therefore attacker-controlled, and an admin allowlist checked against
|
|
254
|
+
* them is checked against nothing.
|
|
255
|
+
*
|
|
256
|
+
* Reads and writes through `from()` are unaffected: they carry the access
|
|
257
|
+
* token to the backend, which verifies it under RLS. It is the decisions
|
|
258
|
+
* your own app takes from `session.user` that are forgeable.
|
|
259
|
+
*
|
|
260
|
+
* `getUser()` costs one round trip and returns the user the backend
|
|
261
|
+
* confirms, in the same `{ data, error }` shape. Prefer it everywhere but a
|
|
262
|
+
* cosmetic "am I probably signed in" check.
|
|
263
|
+
*/
|
|
180
264
|
getSession(): Promise<MotherbaseResponse<{
|
|
181
265
|
session: Session | null;
|
|
182
266
|
}>>;
|
|
183
267
|
/**
|
|
184
268
|
* Revalidate the current session against the server. Better Auth bearer
|
|
185
|
-
* sessions have no refresh token
|
|
269
|
+
* sessions have no refresh token: if the session is still valid the user is
|
|
186
270
|
* refreshed; otherwise the local session is cleared.
|
|
187
271
|
*/
|
|
188
272
|
refreshSession(): Promise<MotherbaseResponse<{
|
|
189
273
|
user: User | null;
|
|
190
274
|
session: Session | null;
|
|
191
275
|
}>>;
|
|
276
|
+
/**
|
|
277
|
+
* Subscribe to auth changes, supabase-js style.
|
|
278
|
+
*
|
|
279
|
+
* The callback fires once with `INITIAL_SESSION` as soon as the stored
|
|
280
|
+
* session has been read, before any later event. That first call is not a
|
|
281
|
+
* nicety: the standard Supabase bootstrap is
|
|
282
|
+
* `if (event === 'INITIAL_SESSION') setLoading(false)`, and without it the
|
|
283
|
+
* app renders its loading state forever for a signed-out visitor, who never
|
|
284
|
+
* produces any other event.
|
|
285
|
+
*
|
|
286
|
+
* It is delivered asynchronously (after hydration), so unsubscribing
|
|
287
|
+
* synchronously suppresses it, exactly as in supabase-js.
|
|
288
|
+
*/
|
|
289
|
+
/**
|
|
290
|
+
* The providers linked to the signed-in user, in the supabase-js identity
|
|
291
|
+
* shape. Backed by Better Auth's `list-accounts`, which is why `email` shows
|
|
292
|
+
* up as an identity for a password account: it is a real linked credential,
|
|
293
|
+
* exactly as in Supabase.
|
|
294
|
+
*/
|
|
295
|
+
getUserIdentities(): Promise<MotherbaseResponse<{
|
|
296
|
+
identities: UserIdentity[];
|
|
297
|
+
}>>;
|
|
298
|
+
/**
|
|
299
|
+
* Link another provider to the signed-in user. Like `signInWithOAuth`, this
|
|
300
|
+
* only starts the flow: the browser is sent to the provider and comes back
|
|
301
|
+
* through the callback.
|
|
302
|
+
*/
|
|
303
|
+
linkIdentity(credentials: SignInWithOAuthCredentials): Promise<MotherbaseResponse<{
|
|
304
|
+
provider: string;
|
|
305
|
+
url: string | null;
|
|
306
|
+
}>>;
|
|
307
|
+
/** Unlink a provider from the signed-in user. */
|
|
308
|
+
unlinkIdentity(identity: {
|
|
309
|
+
provider: string;
|
|
310
|
+
id?: string;
|
|
311
|
+
identity_id?: string;
|
|
312
|
+
}): Promise<MotherbaseResponse<Record<string, never>>>;
|
|
313
|
+
/**
|
|
314
|
+
* Native mobile sign-in with a provider id token (Sign in with Apple, Google
|
|
315
|
+
* One Tap), routed to Better Auth's social sign-in with an `idToken`.
|
|
316
|
+
* The provider must be configured on the backend.
|
|
317
|
+
*/
|
|
318
|
+
signInWithIdToken(params: {
|
|
319
|
+
provider: string;
|
|
320
|
+
token: string;
|
|
321
|
+
access_token?: string;
|
|
322
|
+
nonce?: string;
|
|
323
|
+
}): Promise<MotherbaseResponse<{
|
|
324
|
+
user: User | null;
|
|
325
|
+
session: Session | null;
|
|
326
|
+
}>>;
|
|
327
|
+
/**
|
|
328
|
+
* Claims for the current session, as a JWT payload.
|
|
329
|
+
*
|
|
330
|
+
* supabase-js reads them out of the access token, which is itself a JWT.
|
|
331
|
+
* A Better Auth session token is an opaque bearer, so this asks the server's
|
|
332
|
+
* jwt plugin to mint one and decodes it. The decode is NOT a verification:
|
|
333
|
+
* the token came from the authenticated endpoint over TLS, and a client
|
|
334
|
+
* verifying a token it just asked for proves nothing. Verify server side,
|
|
335
|
+
* against `/api/auth/jwks`.
|
|
336
|
+
*/
|
|
337
|
+
getClaims(): Promise<MotherbaseResponse<{
|
|
338
|
+
claims: Record<string, unknown>;
|
|
339
|
+
token: string;
|
|
340
|
+
}>>;
|
|
341
|
+
/**
|
|
342
|
+
* Revalidate the session on a timer, the way supabase-js does while the tab
|
|
343
|
+
* is focused. Motherbase refreshes on a 401 already, so this is opt-in: it
|
|
344
|
+
* exists so a ported app that calls it keeps working, and so a long-lived
|
|
345
|
+
* screen notices a revoked session without waiting for its next request.
|
|
346
|
+
*/
|
|
347
|
+
startAutoRefresh(intervalMs?: number): void;
|
|
348
|
+
/** Stop the timer started by `startAutoRefresh`. Safe to call when none runs. */
|
|
349
|
+
stopAutoRefresh(): void;
|
|
192
350
|
onAuthStateChange(callback: AuthChangeListener): {
|
|
193
351
|
data: {
|
|
194
352
|
subscription: Subscription;
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"
|
|
1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