@krak-stack/auth 0.2.25 → 0.2.26
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/CHANGELOG.md +6 -0
- package/README.md +25 -0
- package/dist/api.d.ts +36 -0
- package/dist/auth/api.group.d.ts +16 -0
- package/dist/auth/schema.d.ts +11 -0
- package/dist/auth/schema.js +3 -1
- package/dist/components/auth-atoms.d.ts +66 -2
- package/dist/components/auth-atoms.js +12 -3
- package/dist/components/auth-client-api.d.ts +16 -0
- package/dist/components/auth-provider.d.ts +2 -1
- package/dist/components/auth-provider.js +29 -3
- package/dist/schema.d.ts +3 -0
- package/dist/schema.js +5 -0
- package/dist/server/api.group.d.ts +4 -0
- package/dist/server/schema.d.ts +2 -0
- package/dist/service.d.ts +40 -0
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AsyncResult, Atom } from "effect/reactivity";
|
|
2
2
|
export declare const AUTH_CLIENT_CHANGE_EVENT = "krakstack-auth:change";
|
|
3
3
|
export declare const refreshOnAuthChange: <A>(atom: Atom.Atom<A>) => Atom.Atom<A>;
|
|
4
|
-
export declare const authSessionAtom: (arg: string | undefined) => Atom.
|
|
4
|
+
export declare const authSessionAtom: (arg: string | undefined) => Atom.Writable<AsyncResult.AsyncResult<{
|
|
5
5
|
readonly session: {
|
|
6
6
|
readonly id: string;
|
|
7
7
|
readonly expiresAt: Date;
|
|
@@ -20,6 +20,7 @@ export declare const authSessionAtom: (arg: string | undefined) => Atom.Atom<Asy
|
|
|
20
20
|
readonly name: string;
|
|
21
21
|
readonly email: string;
|
|
22
22
|
readonly emailVerified: boolean;
|
|
23
|
+
readonly locale?: "en" | "fr" | undefined;
|
|
23
24
|
readonly image: string | null;
|
|
24
25
|
readonly metadata?: {
|
|
25
26
|
readonly emails?: readonly {
|
|
@@ -62,7 +63,70 @@ export declare const authSessionAtom: (arg: string | undefined) => Atom.Atom<Asy
|
|
|
62
63
|
readonly createdAt: Date;
|
|
63
64
|
readonly updatedAt: Date;
|
|
64
65
|
};
|
|
65
|
-
} | null, import("../auth/schema.js").AuthBadRequest | import("../auth/schema.js").AuthConflict | import("../auth/schema.js").AuthExpectationFailed | import("../auth/schema.js").AuthForbidden | import("../auth/schema.js").AuthInternalServerError | import("../auth/schema.js").AuthNotFound | import("../auth/schema.js").AuthTooManyRequests | import("../auth/schema.js").AuthUnauthorized
|
|
66
|
+
} | null, import("../auth/schema.js").AuthBadRequest | import("../auth/schema.js").AuthConflict | import("../auth/schema.js").AuthExpectationFailed | import("../auth/schema.js").AuthForbidden | import("../auth/schema.js").AuthInternalServerError | import("../auth/schema.js").AuthNotFound | import("../auth/schema.js").AuthTooManyRequests | import("../auth/schema.js").AuthUnauthorized>, Atom.Atom<AsyncResult.AsyncResult<AsyncResult.AsyncResult<{
|
|
67
|
+
readonly session: {
|
|
68
|
+
readonly id: string;
|
|
69
|
+
readonly expiresAt: Date;
|
|
70
|
+
readonly token: string;
|
|
71
|
+
readonly createdAt: Date;
|
|
72
|
+
readonly updatedAt: Date;
|
|
73
|
+
readonly ipAddress?: string | null | undefined;
|
|
74
|
+
readonly userAgent?: string | null | undefined;
|
|
75
|
+
readonly userId: string;
|
|
76
|
+
readonly impersonatedBy?: string | null | undefined;
|
|
77
|
+
readonly impersonatedByOrganizationId?: string | null | undefined;
|
|
78
|
+
readonly activeOrganizationId?: string | null | undefined;
|
|
79
|
+
};
|
|
80
|
+
readonly user: {
|
|
81
|
+
readonly id: string;
|
|
82
|
+
readonly name: string;
|
|
83
|
+
readonly email: string;
|
|
84
|
+
readonly emailVerified: boolean;
|
|
85
|
+
readonly locale?: "en" | "fr" | undefined;
|
|
86
|
+
readonly image: string | null;
|
|
87
|
+
readonly metadata?: {
|
|
88
|
+
readonly emails?: readonly {
|
|
89
|
+
readonly email: string;
|
|
90
|
+
readonly translations: readonly {
|
|
91
|
+
readonly locale: "en" | "fr";
|
|
92
|
+
readonly label: string;
|
|
93
|
+
}[];
|
|
94
|
+
}[] | undefined;
|
|
95
|
+
readonly phones?: readonly {
|
|
96
|
+
readonly number: string;
|
|
97
|
+
readonly extension?: string | undefined;
|
|
98
|
+
readonly translations: readonly {
|
|
99
|
+
readonly locale: "en" | "fr";
|
|
100
|
+
readonly label: string;
|
|
101
|
+
}[];
|
|
102
|
+
}[] | undefined;
|
|
103
|
+
readonly websites?: readonly {
|
|
104
|
+
readonly url: string;
|
|
105
|
+
readonly translations: readonly {
|
|
106
|
+
readonly locale: "en" | "fr";
|
|
107
|
+
readonly label: string;
|
|
108
|
+
}[];
|
|
109
|
+
}[] | undefined;
|
|
110
|
+
readonly socials?: readonly {
|
|
111
|
+
readonly platform: "facebook" | "github" | "instagram" | "linkedin" | "tiktok" | "x" | "youtube";
|
|
112
|
+
readonly url: string;
|
|
113
|
+
readonly translations: readonly {
|
|
114
|
+
readonly locale: "en" | "fr";
|
|
115
|
+
readonly label: string;
|
|
116
|
+
}[];
|
|
117
|
+
}[] | undefined;
|
|
118
|
+
} | null | undefined;
|
|
119
|
+
readonly role: string | null;
|
|
120
|
+
readonly banned: boolean | null;
|
|
121
|
+
readonly banReason?: string | null | undefined;
|
|
122
|
+
readonly banExpires?: Date | null | undefined;
|
|
123
|
+
readonly twoFactorEnabled?: boolean | undefined;
|
|
124
|
+
readonly lastLoginMethod?: string | null | undefined;
|
|
125
|
+
readonly createdAt: Date;
|
|
126
|
+
readonly updatedAt: Date;
|
|
127
|
+
};
|
|
128
|
+
} | null, import("../auth/schema.js").AuthBadRequest | import("../auth/schema.js").AuthConflict | import("../auth/schema.js").AuthExpectationFailed | import("../auth/schema.js").AuthForbidden | import("../auth/schema.js").AuthInternalServerError | import("../auth/schema.js").AuthNotFound | import("../auth/schema.js").AuthTooManyRequests | import("../auth/schema.js").AuthUnauthorized>, unknown>>>;
|
|
129
|
+
export declare const updateUserLocaleAtom: (arg: string | undefined) => Atom.AtomResultFn<"en" | "fr", void, import("../auth/schema.js").AuthBadRequest | import("../auth/schema.js").AuthConflict | import("../auth/schema.js").AuthExpectationFailed | import("../auth/schema.js").AuthForbidden | import("../auth/schema.js").AuthInternalServerError | import("../auth/schema.js").AuthNotFound | import("../auth/schema.js").AuthTooManyRequests | import("../auth/schema.js").AuthUnauthorized | import("effect/http/HttpClientError").HttpClientError | import("effect/Schema").SchemaError>;
|
|
66
130
|
export declare const authOrganizationsAtom: (arg: string | undefined) => Atom.Atom<AsyncResult.AsyncResult<readonly {
|
|
67
131
|
readonly id: string;
|
|
68
132
|
readonly name: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Option } from "effect";
|
|
1
|
+
import { Effect, Option } from "effect";
|
|
2
2
|
import { AsyncResult, Atom } from "effect/reactivity";
|
|
3
|
-
import { authClientApi } from "./auth-client-api.js";
|
|
3
|
+
import { authClientApi, authHttpClient } from "./auth-client-api.js";
|
|
4
4
|
const LAST_LOGIN_METHOD_COOKIE = "krakstack-auth.last_used_login_method";
|
|
5
5
|
export const AUTH_CLIENT_CHANGE_EVENT = "krakstack-auth:change";
|
|
6
6
|
const authRevalidationSignal = Atom.make((get) => {
|
|
@@ -29,7 +29,16 @@ export const authSessionAtom = Atom.family((baseUrl) => Atom.optimistic(authClie
|
|
|
29
29
|
return unauthorized && !result.waiting
|
|
30
30
|
? AsyncResult.success(null)
|
|
31
31
|
: result;
|
|
32
|
-
}))
|
|
32
|
+
}))
|
|
33
|
+
.pipe(refreshOnAuthChange)));
|
|
34
|
+
export const updateUserLocaleAtom = Atom.family((baseUrl) => Atom.optimisticFn(authSessionAtom(baseUrl), {
|
|
35
|
+
reducer: (state, locale) => AsyncResult.map(state, (session) => session ? { ...session, user: { ...session.user, locale } } : session),
|
|
36
|
+
fn: authClientApi(baseUrl).runtime.fn((locale) => Effect.gen(function* () {
|
|
37
|
+
const client = yield* authHttpClient(baseUrl);
|
|
38
|
+
yield* client.auth.updateUser({ payload: { locale } });
|
|
39
|
+
notifyAuthChange();
|
|
40
|
+
})),
|
|
41
|
+
}));
|
|
33
42
|
export const authOrganizationsAtom = Atom.family((baseUrl) => Atom.optimistic(authClientApi(baseUrl).query("auth", "organizationList", {
|
|
34
43
|
timeToLive: "1 minute",
|
|
35
44
|
reactivityKeys: ["auth-organizations"],
|
|
@@ -432,6 +432,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
432
432
|
readonly name: import("effect/Schema").String;
|
|
433
433
|
readonly email: import("effect/Schema").String;
|
|
434
434
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
435
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
435
436
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
436
437
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
437
438
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -496,6 +497,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
496
497
|
readonly name: import("effect/Schema").String;
|
|
497
498
|
readonly email: import("effect/Schema").String;
|
|
498
499
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
500
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
499
501
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
500
502
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
501
503
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -558,6 +560,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
558
560
|
readonly name: import("effect/Schema").String;
|
|
559
561
|
readonly email: import("effect/Schema").String;
|
|
560
562
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
563
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
561
564
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
562
565
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
563
566
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -609,6 +612,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
609
612
|
readonly name: import("effect/Schema").String;
|
|
610
613
|
readonly email: import("effect/Schema").String;
|
|
611
614
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
615
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
612
616
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
613
617
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
614
618
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -706,6 +710,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
706
710
|
readonly name: import("effect/Schema").String;
|
|
707
711
|
readonly email: import("effect/Schema").String;
|
|
708
712
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
713
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
709
714
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
710
715
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
711
716
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -771,6 +776,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
771
776
|
readonly name: import("effect/Schema").String;
|
|
772
777
|
readonly email: import("effect/Schema").String;
|
|
773
778
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
779
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
774
780
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
775
781
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
776
782
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -838,6 +844,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
838
844
|
readonly name: import("effect/Schema").String;
|
|
839
845
|
readonly email: import("effect/Schema").String;
|
|
840
846
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
847
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
841
848
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
842
849
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
843
850
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -1076,6 +1083,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
1076
1083
|
readonly name: import("effect/Schema").String;
|
|
1077
1084
|
readonly email: import("effect/Schema").String;
|
|
1078
1085
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
1086
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
1079
1087
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
1080
1088
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
1081
1089
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -1352,6 +1360,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
1352
1360
|
readonly name: import("effect/Schema").String;
|
|
1353
1361
|
readonly email: import("effect/Schema").String;
|
|
1354
1362
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
1363
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
1355
1364
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
1356
1365
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
1357
1366
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -1411,6 +1420,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
1411
1420
|
readonly name: import("effect/Schema").String;
|
|
1412
1421
|
readonly email: import("effect/Schema").String;
|
|
1413
1422
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
1423
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
1414
1424
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
1415
1425
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
1416
1426
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -1488,6 +1498,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
1488
1498
|
readonly name: import("effect/Schema").String;
|
|
1489
1499
|
readonly email: import("effect/Schema").String;
|
|
1490
1500
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
1501
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
1491
1502
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
1492
1503
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
1493
1504
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -1564,6 +1575,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
1564
1575
|
readonly name: import("effect/Schema").String;
|
|
1565
1576
|
readonly email: import("effect/Schema").String;
|
|
1566
1577
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
1578
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
1567
1579
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
1568
1580
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
1569
1581
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -1618,6 +1630,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
1618
1630
|
readonly name: import("effect/Schema").String;
|
|
1619
1631
|
readonly email: import("effect/Schema").String;
|
|
1620
1632
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
1633
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
1621
1634
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
1622
1635
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
1623
1636
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -1672,6 +1685,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
1672
1685
|
readonly name: import("effect/Schema").String;
|
|
1673
1686
|
readonly email: import("effect/Schema").String;
|
|
1674
1687
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
1688
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
1675
1689
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
1676
1690
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
1677
1691
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -1722,6 +1736,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
1722
1736
|
readonly status: import("effect/Schema").Boolean;
|
|
1723
1737
|
}>>, import("effect/Schema").toCodecJson<typeof import("../auth/schema.js").AuthBadRequest | typeof import("../auth/schema.js").AuthUnauthorized | typeof import("../auth/schema.js").AuthForbidden | typeof import("../auth/schema.js").AuthNotFound | typeof import("../auth/schema.js").AuthConflict | typeof import("../auth/schema.js").AuthExpectationFailed | typeof import("../auth/schema.js").AuthTooManyRequests | typeof import("../auth/schema.js").AuthInternalServerError>, never, never>, never, never>;
|
|
1724
1738
|
readonly updateUser: HttpApiClient.Client.Method<import("effect/http-api/HttpApiEndpoint").HttpApiEndpoint<"updateUser", "POST", "/api/auth/update-user", never, never, import("effect/Schema").toCodecJson<import("effect/Schema").Struct<{
|
|
1739
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
1725
1740
|
readonly name: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
1726
1741
|
readonly image: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
1727
1742
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Struct<{
|
|
@@ -1770,6 +1785,7 @@ export declare const authHttpClient: (baseUrl?: string | undefined, getLocale?:
|
|
|
1770
1785
|
readonly name: import("effect/Schema").String;
|
|
1771
1786
|
readonly email: import("effect/Schema").String;
|
|
1772
1787
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
1788
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
1773
1789
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
1774
1790
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
1775
1791
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -17,6 +17,7 @@ export type KrakstackAuthProviderProps = {
|
|
|
17
17
|
projectId?: string | null | undefined;
|
|
18
18
|
access?: ProjectAccessCatalog | undefined;
|
|
19
19
|
accessLabels?: ProjectAccessLabelCatalog | undefined;
|
|
20
|
+
onLocaleSyncError?: ((cause: typeof Schema.Unknown.Type) => void) | undefined;
|
|
20
21
|
};
|
|
21
22
|
export type KrakstackAuthContextValue = {
|
|
22
23
|
locale: KrakstackAuthLocale;
|
|
@@ -35,7 +36,7 @@ type ProjectConfigState = {
|
|
|
35
36
|
};
|
|
36
37
|
export declare const resolveProjectConfigState: (result: AsyncResult.AsyncResult<ExtraProjectPublicConfig | null, unknown>) => ProjectConfigState;
|
|
37
38
|
export declare const resolveKrakstackAuthLocale: (locale: string) => KrakstackAuthLocale;
|
|
38
|
-
export declare function KrakstackAuthProvider({ children, baseUrl, projectId, access, accessLabels, }: KrakstackAuthProviderProps): import("react").JSX.Element;
|
|
39
|
+
export declare function KrakstackAuthProvider({ children, baseUrl, projectId, access, accessLabels, onLocaleSyncError, }: KrakstackAuthProviderProps): import("react").JSX.Element;
|
|
39
40
|
export declare const useKrakstackAuth: () => KrakstackAuthContextValue | null;
|
|
40
41
|
export declare const useKrakstackAuthProjectConfig: () => {
|
|
41
42
|
readonly projectKey: string;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useAtomValue } from "@effect/atom-react";
|
|
2
|
+
import { useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
3
3
|
import { useRouterState } from "@tanstack/react-router";
|
|
4
4
|
import { Cause, Option, Schema } from "effect";
|
|
5
5
|
import { HttpApiError } from "effect/http-api";
|
|
6
6
|
import { AsyncResult, Atom } from "effect/reactivity";
|
|
7
7
|
import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
|
|
8
8
|
import { createContext, useContext, useEffect, useMemo, useRef, } from "react";
|
|
9
|
-
import { activeAuthOrganizationAtom, authSessionAtom } from "./auth-atoms.js";
|
|
9
|
+
import { activeAuthOrganizationAtom, authSessionAtom, updateUserLocaleAtom, } from "./auth-atoms.js";
|
|
10
10
|
import { authClientApi } from "./auth-client-api.js";
|
|
11
11
|
import { parseRoleList } from "../roles.js";
|
|
12
12
|
export class KrakstackAuthUnavailableError extends Schema.TaggedError()("KrakstackAuthUnavailableError", {
|
|
@@ -106,7 +106,7 @@ const useProjectConfigState = (baseUrl, providedProjectId) => {
|
|
|
106
106
|
const result = useAtomValue(projectConfigAtom);
|
|
107
107
|
return useMemo(() => resolveProjectConfigState(result), [result]);
|
|
108
108
|
};
|
|
109
|
-
export function KrakstackAuthProvider({ children, baseUrl, projectId, access, accessLabels, }) {
|
|
109
|
+
export function KrakstackAuthProvider({ children, baseUrl, projectId, access, accessLabels, onLocaleSyncError, }) {
|
|
110
110
|
const locale = resolveKrakstackAuthLocale(useKrakstackLocale());
|
|
111
111
|
const searchString = useRouterState({
|
|
112
112
|
select: (state) => state.location.searchStr,
|
|
@@ -115,7 +115,33 @@ export function KrakstackAuthProvider({ children, baseUrl, projectId, access, ac
|
|
|
115
115
|
const projectConfigState = useProjectConfigState(baseUrl, projectId);
|
|
116
116
|
const sessionAtom = authSessionAtom(baseUrl);
|
|
117
117
|
const sessionResult = useAtomValue(sessionAtom);
|
|
118
|
+
const saveLocale = useAtomSet(updateUserLocaleAtom(baseUrl), {
|
|
119
|
+
mode: "promise",
|
|
120
|
+
});
|
|
121
|
+
const lastLocaleSyncKey = useRef(null);
|
|
118
122
|
const wasAuthenticated = useRef(false);
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (!AsyncResult.isSuccess(sessionResult) || sessionResult.waiting)
|
|
125
|
+
return;
|
|
126
|
+
const session = sessionResult.value;
|
|
127
|
+
if (!session ||
|
|
128
|
+
session.session.impersonatedBy ||
|
|
129
|
+
session.session.impersonatedByOrganizationId) {
|
|
130
|
+
lastLocaleSyncKey.current = null;
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const key = `${session.user.id}:${locale}`;
|
|
134
|
+
if (lastLocaleSyncKey.current === key)
|
|
135
|
+
return;
|
|
136
|
+
// Keep the key through optimistic updates and rollback to avoid retry loops.
|
|
137
|
+
lastLocaleSyncKey.current = key;
|
|
138
|
+
if (session.user.locale === locale)
|
|
139
|
+
return;
|
|
140
|
+
void saveLocale(locale).catch((cause) => {
|
|
141
|
+
console.error("Failed to sync account language", cause);
|
|
142
|
+
onLocaleSyncError?.(cause);
|
|
143
|
+
});
|
|
144
|
+
}, [locale, sessionResult, saveLocale, onLocaleSyncError]);
|
|
119
145
|
useEffect(() => {
|
|
120
146
|
if (!AsyncResult.isSuccess(sessionResult) || sessionResult.waiting)
|
|
121
147
|
return;
|
package/dist/schema.d.ts
CHANGED
|
@@ -246,11 +246,13 @@ export declare const UserMetadataStandard: import("effect/StandardSchema").Stand
|
|
|
246
246
|
}>>;
|
|
247
247
|
}>>>;
|
|
248
248
|
}>;
|
|
249
|
+
export declare const UserLocale: Schema.Literals<readonly ["en", "fr"]>;
|
|
249
250
|
export declare const User: Schema.Struct<{
|
|
250
251
|
readonly id: Schema.String;
|
|
251
252
|
readonly name: Schema.String;
|
|
252
253
|
readonly email: Schema.String;
|
|
253
254
|
readonly emailVerified: Schema.Boolean;
|
|
255
|
+
readonly locale: Schema.optional<Schema.Literals<readonly ["en", "fr"]>>;
|
|
254
256
|
readonly image: Schema.NullOr<Schema.String>;
|
|
255
257
|
readonly metadata: Schema.optional<Schema.NullOr<Schema.decodeTo<Schema.Struct<{
|
|
256
258
|
readonly emails: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
@@ -450,6 +452,7 @@ export declare const Member: Schema.Struct<{
|
|
|
450
452
|
readonly name: Schema.String;
|
|
451
453
|
readonly email: Schema.String;
|
|
452
454
|
readonly emailVerified: Schema.Boolean;
|
|
455
|
+
readonly locale: Schema.optional<Schema.Literals<readonly ["en", "fr"]>>;
|
|
453
456
|
readonly image: Schema.NullOr<Schema.String>;
|
|
454
457
|
readonly metadata: Schema.optional<Schema.NullOr<Schema.decodeTo<Schema.Struct<{
|
|
455
458
|
readonly emails: Schema.optional<Schema.$Array<Schema.Struct<{
|
package/dist/schema.js
CHANGED
|
@@ -212,11 +212,16 @@ const CompatibleUserMetadata = Schema.Unknown.pipe(Schema.decodeTo(UserMetadata,
|
|
|
212
212
|
}),
|
|
213
213
|
encode: SchemaGetter.transform((metadata) => metadata),
|
|
214
214
|
}));
|
|
215
|
+
export const UserLocale = Schema.Literals(["en", "fr"]).annotate({
|
|
216
|
+
identifier: "UserLocale",
|
|
217
|
+
description: "Preferred language for the interface and communications.",
|
|
218
|
+
});
|
|
215
219
|
export const User = Schema.Struct({
|
|
216
220
|
id: Schema.String,
|
|
217
221
|
name: Schema.String,
|
|
218
222
|
email: Schema.String,
|
|
219
223
|
emailVerified: Schema.Boolean,
|
|
224
|
+
locale: Schema.optional(UserLocale),
|
|
220
225
|
image: Schema.NullOr(Schema.String),
|
|
221
226
|
metadata: Schema.optional(Schema.NullOr(CompatibleUserMetadata)),
|
|
222
227
|
role: Schema.NullOr(Schema.String),
|
|
@@ -6,6 +6,7 @@ export declare const ServerUsersApiGroup: HttpApiGroup.HttpApiGroup<"users", Htt
|
|
|
6
6
|
readonly name: import("effect/Schema").String;
|
|
7
7
|
readonly email: import("effect/Schema").String;
|
|
8
8
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
9
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
9
10
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
10
11
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
11
12
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -56,6 +57,7 @@ export declare const ServerUsersApiGroup: HttpApiGroup.HttpApiGroup<"users", Htt
|
|
|
56
57
|
readonly name: import("effect/Schema").String;
|
|
57
58
|
readonly email: import("effect/Schema").String;
|
|
58
59
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
60
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
59
61
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
60
62
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
61
63
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -111,6 +113,7 @@ export declare const ServerOrganizationsApiGroup: HttpApiGroup.HttpApiGroup<"org
|
|
|
111
113
|
readonly name: import("effect/Schema").String;
|
|
112
114
|
readonly email: import("effect/Schema").String;
|
|
113
115
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
116
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
114
117
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
115
118
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
116
119
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
@@ -283,6 +286,7 @@ export declare const ServerOrganizationsApiGroup: HttpApiGroup.HttpApiGroup<"org
|
|
|
283
286
|
readonly name: import("effect/Schema").String;
|
|
284
287
|
readonly email: import("effect/Schema").String;
|
|
285
288
|
readonly emailVerified: import("effect/Schema").Boolean;
|
|
289
|
+
readonly locale: import("effect/Schema").optional<import("effect/Schema").Literals<readonly ["en", "fr"]>>;
|
|
286
290
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
287
291
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").decodeTo<import("effect/Schema").Struct<{
|
|
288
292
|
readonly emails: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
package/dist/server/schema.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export declare const ServerUsersResponse: Schema.Struct<{
|
|
|
33
33
|
readonly name: Schema.String;
|
|
34
34
|
readonly email: Schema.String;
|
|
35
35
|
readonly emailVerified: Schema.Boolean;
|
|
36
|
+
readonly locale: Schema.optional<Schema.Literals<readonly ["en", "fr"]>>;
|
|
36
37
|
readonly image: Schema.NullOr<Schema.String>;
|
|
37
38
|
readonly metadata: Schema.optional<Schema.NullOr<Schema.decodeTo<Schema.Struct<{
|
|
38
39
|
readonly emails: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
@@ -206,6 +207,7 @@ export declare const ServerMembersResponse: Schema.$Array<Schema.Struct<{
|
|
|
206
207
|
readonly name: Schema.String;
|
|
207
208
|
readonly email: Schema.String;
|
|
208
209
|
readonly emailVerified: Schema.Boolean;
|
|
210
|
+
readonly locale: Schema.optional<Schema.Literals<readonly ["en", "fr"]>>;
|
|
209
211
|
readonly image: Schema.NullOr<Schema.String>;
|
|
210
212
|
readonly metadata: Schema.optional<Schema.NullOr<Schema.decodeTo<Schema.Struct<{
|
|
211
213
|
readonly emails: Schema.optional<Schema.$Array<Schema.Struct<{
|