@supa-media/convex 1.2.1 → 1.3.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/package.json +1 -1
- package/src/auth/index.ts +6 -1
- package/src/auth/setup.ts +54 -0
- package/src/index.ts +2 -0
package/package.json
CHANGED
package/src/auth/index.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
createSupaAuth,
|
|
3
|
+
MAGIC_LINK_PROVIDER_ID,
|
|
4
|
+
TEST_EMAIL_PROVIDER_ID,
|
|
5
|
+
} from "./setup";
|
|
2
6
|
export type {
|
|
3
7
|
SupaAuthConfig,
|
|
4
8
|
SupaAuthMagicLinkConfig,
|
|
5
9
|
SupaAuthResendConfig,
|
|
10
|
+
SupaAuthTestEmailConfig,
|
|
6
11
|
SupaAuthTwilioConfig,
|
|
7
12
|
} from "./setup";
|
|
8
13
|
export {
|
package/src/auth/setup.ts
CHANGED
|
@@ -57,6 +57,16 @@ export interface SupaAuthTwilioConfig {
|
|
|
57
57
|
*/
|
|
58
58
|
export const MAGIC_LINK_PROVIDER_ID = "magic-link";
|
|
59
59
|
|
|
60
|
+
/** Provider id for an explicitly scoped production test account. */
|
|
61
|
+
export const TEST_EMAIL_PROVIDER_ID = "test-email";
|
|
62
|
+
|
|
63
|
+
export interface SupaAuthTestEmailConfig {
|
|
64
|
+
/** The only email address allowed to use the fixed test code. */
|
|
65
|
+
email: string;
|
|
66
|
+
/** Fixed verification code. Defaults to `000000`. */
|
|
67
|
+
code?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
60
70
|
export interface SupaAuthMagicLinkConfig {
|
|
61
71
|
/**
|
|
62
72
|
* How long a link stays live, in seconds. Defaults to one hour.
|
|
@@ -100,6 +110,12 @@ export interface SupaAuthConfig {
|
|
|
100
110
|
* `MAGIC_LINK_PROVIDER_ID` for what it does and does not change.
|
|
101
111
|
*/
|
|
102
112
|
magicLink?: SupaAuthMagicLinkConfig;
|
|
113
|
+
/**
|
|
114
|
+
* Register a fixed-code provider for one exact test account.
|
|
115
|
+
* Unlike `DEV_OTP_BYPASS`, this may be used in production because every
|
|
116
|
+
* other email address is refused by a distinct provider.
|
|
117
|
+
*/
|
|
118
|
+
testEmail?: SupaAuthTestEmailConfig;
|
|
103
119
|
/** Resend email OTP configuration. */
|
|
104
120
|
resend?: SupaAuthResendConfig;
|
|
105
121
|
/** Twilio phone OTP configuration. */
|
|
@@ -193,6 +209,41 @@ function createEmailOtp(config: SupaAuthConfig) {
|
|
|
193
209
|
});
|
|
194
210
|
}
|
|
195
211
|
|
|
212
|
+
/** Build the fixed-code provider separately so its security boundary is testable. */
|
|
213
|
+
export function createTestEmailOtp(config: SupaAuthTestEmailConfig) {
|
|
214
|
+
const email = config.email.trim().toLowerCase();
|
|
215
|
+
const code = config.code ?? DEV_BYPASS_CODE;
|
|
216
|
+
if (!/^\d{6}$/.test(code)) {
|
|
217
|
+
throw new Error("testEmail.code must be exactly six digits");
|
|
218
|
+
}
|
|
219
|
+
if (email.length === 0) {
|
|
220
|
+
throw new Error("testEmail.email must not be empty");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const provider = Email({
|
|
224
|
+
maxAge: 10 * 60,
|
|
225
|
+
generateVerificationToken: () => code,
|
|
226
|
+
sendVerificationRequest: async ({ identifier }) => {
|
|
227
|
+
if (identifier.trim().toLowerCase() !== email) {
|
|
228
|
+
throw new Error("This test sign-in provider is not available for that email.");
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
return {
|
|
233
|
+
...provider,
|
|
234
|
+
id: TEST_EMAIL_PROVIDER_ID,
|
|
235
|
+
authorize: async (params: Record<string, unknown>, account: { providerAccountId: string }) => {
|
|
236
|
+
if (
|
|
237
|
+
typeof params.email !== "string" ||
|
|
238
|
+
params.email.trim().toLowerCase() !== email ||
|
|
239
|
+
account.providerAccountId.trim().toLowerCase() !== email
|
|
240
|
+
) {
|
|
241
|
+
throw new Error("This test sign-in provider is not available for that email.");
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
196
247
|
/**
|
|
197
248
|
* The link-only email provider.
|
|
198
249
|
*
|
|
@@ -407,6 +458,9 @@ export function createSupaAuth(config: SupaAuthConfig = {}) {
|
|
|
407
458
|
...(methods.includes("email") && config.magicLink !== undefined
|
|
408
459
|
? [createMagicLink(config)]
|
|
409
460
|
: []),
|
|
461
|
+
...(methods.includes("email") && config.testEmail !== undefined
|
|
462
|
+
? [createTestEmailOtp(config.testEmail)]
|
|
463
|
+
: []),
|
|
410
464
|
...(methods.includes("phone") ? [createPhoneOtp(config)] : []),
|
|
411
465
|
];
|
|
412
466
|
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
export {
|
|
10
10
|
createSupaAuth,
|
|
11
11
|
MAGIC_LINK_PROVIDER_ID,
|
|
12
|
+
TEST_EMAIL_PROVIDER_ID,
|
|
12
13
|
requireAuth,
|
|
13
14
|
requireAuthId,
|
|
14
15
|
getOptionalAuth,
|
|
@@ -18,6 +19,7 @@ export type {
|
|
|
18
19
|
SupaAuthConfig,
|
|
19
20
|
SupaAuthMagicLinkConfig,
|
|
20
21
|
SupaAuthResendConfig,
|
|
22
|
+
SupaAuthTestEmailConfig,
|
|
21
23
|
SupaAuthTwilioConfig,
|
|
22
24
|
} from "./auth";
|
|
23
25
|
|