tinbase 0.19.1 → 0.21.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.
@@ -3,7 +3,7 @@
3
3
  * uses for email/password auth, sessions, and admin user management.
4
4
  */
5
5
  import type { Database } from '../db/database.js';
6
- import { type Mailer, type RequestContext } from '../types.js';
6
+ import { type Mailer, type RequestContext, type SmsSender } from '../types.js';
7
7
  import { type OAuthProviderConfig } from './oauth.js';
8
8
  import { type AuthSettings } from './settings.js';
9
9
  import { type EmailTemplates } from './templates.js';
@@ -42,6 +42,12 @@ export interface AuthConfig {
42
42
  sessionTimeboxSeconds?: number;
43
43
  /** sends outgoing auth email (magic links, OTP codes, recovery) */
44
44
  mailer: Mailer;
45
+ /** sends phone OTP codes (sign-in, signup confirmation, phone change) */
46
+ smsSender: SmsSender;
47
+ /** `[auth.sms] template`; `{{ .Code }}` is the OTP. Default "Your code is {{ .Code }}". */
48
+ smsTemplate?: string;
49
+ /** What `/settings` reports as `sms_provider` (twilio, or the dev inbox / a custom sender). */
50
+ smsProviderName?: string;
45
51
  /**
46
52
  * Per-type HTML overrides from `[auth.email.template.*]`. A project that
47
53
  * supplies one decides for itself what the mail offers - link, code, both, or
@@ -100,6 +106,7 @@ interface UserRow {
100
106
  phone_confirmed_at: Date | string | null;
101
107
  is_anonymous: boolean | null;
102
108
  email_change: string | null;
109
+ phone_change: string | null;
103
110
  }
104
111
  /** Routes and services the GoTrue-compatible `/auth/v1/*` endpoints. */
105
112
  export declare class AuthHandler {
@@ -274,6 +281,51 @@ export declare class AuthHandler {
274
281
  private verifyEmailChange;
275
282
  private verifyToken;
276
283
  private verifyLink;
284
+ /** GoTrue's answer to any phone endpoint while phone auth is off. */
285
+ private static phoneDisabled;
286
+ private static invalidPhone;
287
+ /**
288
+ * `[auth.sms] max_frequency`, measured like {@link limitEmailFrequency}:
289
+ * against the column that flow last wrote on the recipient's row, with an
290
+ * in-memory window for a number that has no row yet.
291
+ */
292
+ private limitSmsFrequency;
293
+ /**
294
+ * Mint a code for `phone`, replacing any live one of the same type, and
295
+ * text it. The send column is written only once the provider accepted the
296
+ * message, as with mail. Returns the provider's message id when it gave one.
297
+ */
298
+ private sendSmsCode;
299
+ /** Create the account a phone OTP is for, with GoTrue's provider metadata. */
300
+ private createPhoneUser;
301
+ /** The `phone` identity GoTrue records, so `user.identities` names the provider. */
302
+ private ensurePhoneIdentity;
303
+ /** `supabase.auth.signUp({ phone, password })`. */
304
+ private signupWithPhone;
305
+ /** `supabase.auth.signInWithOtp({ phone })`: text a code, creating the account unless told not to. */
306
+ private sendPhoneOtp;
307
+ /**
308
+ * `supabase.auth.resend({ phone, type: 'sms' | 'phone_change' })`.
309
+ *
310
+ * Like the email resend: 200 and no text for a number with nothing pending,
311
+ * whether because it has no account, is already confirmed, or has no change
312
+ * under way - so the endpoint cannot be used to find out which.
313
+ */
314
+ private resendSms;
315
+ /**
316
+ * `max_frequency` for a phone change: the account's own `phone_change_sent_at`
317
+ * (the new number has no row to measure by), plus the in-memory window on
318
+ * the new number itself so one account cannot be used to text it in a loop.
319
+ */
320
+ private limitPhoneChangeFrequency;
321
+ /**
322
+ * Begin a phone change: park the new number and text it a code. The number
323
+ * moves only when the code comes back through `/verify` type `phone_change`.
324
+ * Returns a Response only when the change could not be started.
325
+ */
326
+ private startPhoneChange;
327
+ /** `verifyOtp({ phone, token, type: 'sms' | 'phone_change' })` → session. */
328
+ private verifySmsToken;
277
329
  private admin;
278
330
  /**
279
331
  * POST /auth/v1/admin/invite - `auth.admin.inviteUserByEmail`.