@startsimpli/auth 0.4.16 → 0.4.17
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 +17 -14
- package/src/__tests__/auth-client-oauth-register.test.ts +5 -8
- package/src/__tests__/auth-functions.test.ts +0 -1
- package/src/__tests__/useauth-shape-contract.test.ts +0 -1
- package/src/client/__tests__/mock-backend.test.ts +3 -6
- package/src/client/auth-client.ts +59 -2
- package/src/client/auth-context.tsx +62 -7
- package/src/client/backend.ts +10 -1
- package/src/client/functions.ts +31 -5
- package/src/client/mock-backend.ts +0 -3
- package/src/client/use-auth.ts +6 -1
- package/src/components/forgot-password-form.tsx +97 -0
- package/src/components/index.ts +5 -1
- package/src/components/oauth-callback.tsx +5 -2
- package/src/components/reset-password-form.tsx +124 -0
- package/src/components/sign-in-form.tsx +125 -0
- package/src/components/signup-form.tsx +161 -0
- package/src/components/use-oauth-callback.ts +14 -2
- package/src/hooks/__tests__/use-domain-claims.test.tsx +95 -0
- package/src/hooks/__tests__/use-invitations.test.tsx +90 -0
- package/src/hooks/__tests__/use-membership.test.tsx +136 -0
- package/src/hooks/index.ts +34 -0
- package/src/hooks/use-domain-claims.ts +144 -0
- package/src/hooks/use-invitations.ts +138 -0
- package/src/hooks/use-membership.ts +192 -0
- package/src/index.ts +25 -0
- package/src/server/index.ts +4 -0
- package/src/types/index.ts +0 -1
- package/src/utils/central-auth.ts +91 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/validation.ts +10 -21
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for redirecting to the central StartSimpli auth host
|
|
3
|
+
* (auth.startsimpli.com, see startsim-ul0).
|
|
4
|
+
*
|
|
5
|
+
* Per-app auth pages have been replaced by a single host that owns
|
|
6
|
+
* /signin, /signup, /forgot-password, /reset-password, /verify-email,
|
|
7
|
+
* /oauth/google/callback, /oauth/microsoft/callback, /completion, /error.
|
|
8
|
+
*
|
|
9
|
+
* Apps consume this helper to:
|
|
10
|
+
* 1. Build "Sign in" / "Create account" links with the `app` + `return_to`
|
|
11
|
+
* query params preserved.
|
|
12
|
+
* 2. Configure AuthProvider's `loginPath` so session-expired bounces hit the
|
|
13
|
+
* same host.
|
|
14
|
+
*
|
|
15
|
+
* Defaults to https://auth.startsimpli.com but can be overridden via the
|
|
16
|
+
* `NEXT_PUBLIC_AUTH_HOST` env var for staging / local dev.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export const DEFAULT_CENTRAL_AUTH_HOST = 'https://auth.startsimpli.com';
|
|
20
|
+
|
|
21
|
+
/** Flows owned by the central auth host. */
|
|
22
|
+
export type CentralAuthFlow =
|
|
23
|
+
| 'signin'
|
|
24
|
+
| 'signup'
|
|
25
|
+
| 'forgot-password'
|
|
26
|
+
| 'reset-password'
|
|
27
|
+
| 'verify-email'
|
|
28
|
+
| 'completion'
|
|
29
|
+
| 'error';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Resolve the central auth host. Reads `NEXT_PUBLIC_AUTH_HOST` when present
|
|
33
|
+
* so apps can point at a staging deploy without rebuilding the package.
|
|
34
|
+
*/
|
|
35
|
+
export function resolveCentralAuthHost(): string {
|
|
36
|
+
if (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_AUTH_HOST) {
|
|
37
|
+
return process.env.NEXT_PUBLIC_AUTH_HOST;
|
|
38
|
+
}
|
|
39
|
+
return DEFAULT_CENTRAL_AUTH_HOST;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface BuildCentralAuthUrlOptions {
|
|
43
|
+
/** Slug identifying the calling app (e.g. `vault`, `raise`, `market`). */
|
|
44
|
+
app: string;
|
|
45
|
+
/** Absolute URL the user should be returned to after the flow completes. */
|
|
46
|
+
returnTo?: string;
|
|
47
|
+
/** Override the host (otherwise resolved from env). */
|
|
48
|
+
host?: string;
|
|
49
|
+
/** Extra query params to tack on. */
|
|
50
|
+
extraParams?: Record<string, string>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Build a URL into the central auth host, preserving `?app=` and
|
|
55
|
+
* `?return_to=` consistently. Use this for hand-rolled links AND for
|
|
56
|
+
* AuthProvider's `loginPath` config.
|
|
57
|
+
*
|
|
58
|
+
* Example:
|
|
59
|
+
* buildCentralAuthUrl('signin', { app: 'vault', returnTo: 'https://vault.startsimpli.com/environments' })
|
|
60
|
+
* // => 'https://auth.startsimpli.com/signin?app=vault&return_to=https%3A%2F%2F...'
|
|
61
|
+
*/
|
|
62
|
+
export function buildCentralAuthUrl(
|
|
63
|
+
flow: CentralAuthFlow,
|
|
64
|
+
options: BuildCentralAuthUrlOptions,
|
|
65
|
+
): string {
|
|
66
|
+
const host = options.host ?? resolveCentralAuthHost();
|
|
67
|
+
const url = new URL(`/${flow}`, host);
|
|
68
|
+
url.searchParams.set('app', options.app);
|
|
69
|
+
if (options.returnTo) {
|
|
70
|
+
url.searchParams.set('return_to', options.returnTo);
|
|
71
|
+
}
|
|
72
|
+
if (options.extraParams) {
|
|
73
|
+
for (const [key, value] of Object.entries(options.extraParams)) {
|
|
74
|
+
url.searchParams.set(key, value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return url.toString();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Convenience: redirect the browser to the central auth host's signin flow,
|
|
82
|
+
* preserving the current URL as `return_to`. Safe to call from client code.
|
|
83
|
+
*/
|
|
84
|
+
export function redirectToCentralSignin(app: string): void {
|
|
85
|
+
if (typeof window === 'undefined') return;
|
|
86
|
+
const url = buildCentralAuthUrl('signin', {
|
|
87
|
+
app,
|
|
88
|
+
returnTo: window.location.href,
|
|
89
|
+
});
|
|
90
|
+
window.location.href = url;
|
|
91
|
+
}
|
package/src/utils/index.ts
CHANGED
package/src/utils/validation.ts
CHANGED
|
@@ -54,18 +54,13 @@ export const passwordSchema = z
|
|
|
54
54
|
);
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
|
-
* Password
|
|
58
|
-
*
|
|
57
|
+
* Password schema (alias retained for back-compat — passwordConfirm dropped
|
|
58
|
+
* from create-account/reset/change flows since browsers + password managers
|
|
59
|
+
* make the second field pure friction). startsim-nbq.
|
|
59
60
|
*/
|
|
60
|
-
export const passwordConfirmSchema = z
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
passwordConfirm: z.string(),
|
|
64
|
-
})
|
|
65
|
-
.refine((data) => data.password === data.passwordConfirm, {
|
|
66
|
-
message: PasswordErrorCode.MISMATCH,
|
|
67
|
-
path: ['passwordConfirm'],
|
|
68
|
-
});
|
|
61
|
+
export const passwordConfirmSchema = z.object({
|
|
62
|
+
password: passwordSchema,
|
|
63
|
+
});
|
|
69
64
|
|
|
70
65
|
/**
|
|
71
66
|
* Password reset request schema
|
|
@@ -78,16 +73,10 @@ export const passwordResetRequestSchema = z.object({
|
|
|
78
73
|
/**
|
|
79
74
|
* Password reset confirm schema
|
|
80
75
|
*/
|
|
81
|
-
export const passwordResetConfirmSchema = z
|
|
82
|
-
.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
passwordConfirm: z.string(),
|
|
86
|
-
})
|
|
87
|
-
.refine((data) => data.password === data.passwordConfirm, {
|
|
88
|
-
message: PasswordErrorCode.MISMATCH,
|
|
89
|
-
path: ['passwordConfirm'] as const,
|
|
90
|
-
});
|
|
76
|
+
export const passwordResetConfirmSchema = z.object({
|
|
77
|
+
token: z.string().min(1, { message: 'Token is required' }),
|
|
78
|
+
password: passwordSchema,
|
|
79
|
+
});
|
|
91
80
|
|
|
92
81
|
/**
|
|
93
82
|
* Email verification request schema
|