@absolutejs/auth 0.31.0 → 0.33.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/dist/client/solid.d.ts +63 -0
- package/dist/client/solid.js +73 -0
- package/dist/client/solid.js.map +10 -0
- package/dist/client/svelte.d.ts +63 -0
- package/dist/client/svelte.js +61 -0
- package/dist/client/svelte.js.map +10 -0
- package/dist/client/vue.d.ts +63 -0
- package/dist/client/vue.js +73 -0
- package/dist/client/vue.js.map +10 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -7
- package/dist/index.js.map +3 -3
- package/dist/routes/signout.d.ts +1 -1
- package/dist/types.d.ts +5 -1
- package/package.json +31 -4
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type Accessor } from 'solid-js';
|
|
2
|
+
import type { AuthClient, AuthClientError } from './createAuthClient';
|
|
3
|
+
type Mutator<Args, Data> = (args: Args) => Promise<{
|
|
4
|
+
data: Data | null;
|
|
5
|
+
error: AuthClientError | null;
|
|
6
|
+
}>;
|
|
7
|
+
type MutationState<Args, Data> = {
|
|
8
|
+
data: Accessor<Data | null>;
|
|
9
|
+
error: Accessor<AuthClientError | null>;
|
|
10
|
+
isPending: Accessor<boolean>;
|
|
11
|
+
mutate: Mutator<Args, Data>;
|
|
12
|
+
reset: () => void;
|
|
13
|
+
};
|
|
14
|
+
export declare const useMagicLink: (client: AuthClient) => MutationState<{
|
|
15
|
+
email: string;
|
|
16
|
+
}, {
|
|
17
|
+
ok: true;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const useMfaChallenge: (client: AuthClient) => MutationState<{
|
|
20
|
+
code: string;
|
|
21
|
+
}, {
|
|
22
|
+
status: "authenticated";
|
|
23
|
+
}>;
|
|
24
|
+
export declare const usePasswordReset: (client: AuthClient) => MutationState<{
|
|
25
|
+
email: string;
|
|
26
|
+
}, {
|
|
27
|
+
ok: true;
|
|
28
|
+
}>;
|
|
29
|
+
export declare const useSessions: (client: AuthClient) => {
|
|
30
|
+
data: Accessor<unknown[] | null>;
|
|
31
|
+
error: Accessor<AuthClientError | null>;
|
|
32
|
+
isPending: Accessor<boolean>;
|
|
33
|
+
refetch: () => Promise<void>;
|
|
34
|
+
revoke: (sessionId: string) => Promise<{
|
|
35
|
+
data: null;
|
|
36
|
+
error: AuthClientError;
|
|
37
|
+
} | {
|
|
38
|
+
data: {
|
|
39
|
+
ok: true;
|
|
40
|
+
};
|
|
41
|
+
error: null;
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
44
|
+
export declare const useSignIn: (client: AuthClient) => MutationState<{
|
|
45
|
+
email: string;
|
|
46
|
+
password: string;
|
|
47
|
+
}, {
|
|
48
|
+
passwordCompromised?: boolean;
|
|
49
|
+
status: "authenticated" | "mfa_required";
|
|
50
|
+
}>;
|
|
51
|
+
export declare const useSignOut: (client: AuthClient) => MutationState<unknown, {
|
|
52
|
+
ok: true;
|
|
53
|
+
}>;
|
|
54
|
+
export declare const useSignUp: (client: AuthClient) => MutationState<{
|
|
55
|
+
[extra: string]: unknown;
|
|
56
|
+
email: string;
|
|
57
|
+
password: string;
|
|
58
|
+
}, {
|
|
59
|
+
status: "authenticated";
|
|
60
|
+
} | {
|
|
61
|
+
status: "verification_required";
|
|
62
|
+
}>;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/client/solid.ts
|
|
3
|
+
import { createSignal, onCleanup } from "solid-js";
|
|
4
|
+
var useMutation = (run) => {
|
|
5
|
+
const [data, setData] = createSignal(null);
|
|
6
|
+
const [error, setError] = createSignal(null);
|
|
7
|
+
const [isPending, setIsPending] = createSignal(false);
|
|
8
|
+
let alive = true;
|
|
9
|
+
onCleanup(() => {
|
|
10
|
+
alive = false;
|
|
11
|
+
});
|
|
12
|
+
const mutate = async (args) => {
|
|
13
|
+
setIsPending(true);
|
|
14
|
+
setError(null);
|
|
15
|
+
const result = await run(args);
|
|
16
|
+
if (alive) {
|
|
17
|
+
setData(() => result.data);
|
|
18
|
+
setError(result.error);
|
|
19
|
+
setIsPending(false);
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
const reset = () => {
|
|
24
|
+
setData(() => null);
|
|
25
|
+
setError(null);
|
|
26
|
+
setIsPending(false);
|
|
27
|
+
};
|
|
28
|
+
return { data, error, isPending, mutate, reset };
|
|
29
|
+
};
|
|
30
|
+
var useMagicLink = (client) => useMutation(client.passwordless.requestMagicLink);
|
|
31
|
+
var useMfaChallenge = (client) => useMutation(client.mfa.challenge);
|
|
32
|
+
var usePasswordReset = (client) => useMutation(client.passwordReset.request);
|
|
33
|
+
var useSessions = (client) => {
|
|
34
|
+
const [data, setData] = createSignal(null);
|
|
35
|
+
const [error, setError] = createSignal(null);
|
|
36
|
+
const [isPending, setIsPending] = createSignal(true);
|
|
37
|
+
let alive = true;
|
|
38
|
+
onCleanup(() => {
|
|
39
|
+
alive = false;
|
|
40
|
+
});
|
|
41
|
+
const refetch = async () => {
|
|
42
|
+
setIsPending(true);
|
|
43
|
+
const result = await client.sessions.list();
|
|
44
|
+
if (alive) {
|
|
45
|
+
setData(() => result.data);
|
|
46
|
+
setError(result.error);
|
|
47
|
+
setIsPending(false);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const revoke = async (sessionId) => {
|
|
51
|
+
const result = await client.sessions.revoke(sessionId);
|
|
52
|
+
if (result.error === null)
|
|
53
|
+
await refetch();
|
|
54
|
+
return result;
|
|
55
|
+
};
|
|
56
|
+
refetch();
|
|
57
|
+
return { data, error, isPending, refetch, revoke };
|
|
58
|
+
};
|
|
59
|
+
var useSignIn = (client) => useMutation(client.signIn.email);
|
|
60
|
+
var useSignOut = (client) => useMutation(client.signOut);
|
|
61
|
+
var useSignUp = (client) => useMutation(client.signUp.email);
|
|
62
|
+
export {
|
|
63
|
+
useSignUp,
|
|
64
|
+
useSignOut,
|
|
65
|
+
useSignIn,
|
|
66
|
+
useSessions,
|
|
67
|
+
usePasswordReset,
|
|
68
|
+
useMfaChallenge,
|
|
69
|
+
useMagicLink
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//# debugId=C75839665B18FF0264756E2164756E21
|
|
73
|
+
//# sourceMappingURL=solid.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/client/solid.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"// Thin Solid composables over `createAuthClient`, mirroring `./react`. Same `{ data, error,\n// isPending, mutate, reset }` shape — only the reactivity is Solid's (signals + onCleanup).\n// Bring your own form / UI; these are primitives.\n\nimport { createSignal, onCleanup, type Accessor } from 'solid-js';\nimport type { AuthClient, AuthClientError } from './createAuthClient';\n\ntype Mutator<Args, Data> = (\n\targs: Args\n) => Promise<{ data: Data | null; error: AuthClientError | null }>;\n\ntype MutationState<Args, Data> = {\n\tdata: Accessor<Data | null>;\n\terror: Accessor<AuthClientError | null>;\n\tisPending: Accessor<boolean>;\n\tmutate: Mutator<Args, Data>;\n\treset: () => void;\n};\n\n// Generic mutation composable. The exported composables are 1-2 line specializations of\n// this — kept private so consumers depend on the named API, not this internal shape.\nconst useMutation = <Args, Data>(\n\trun: Mutator<Args, Data>\n): MutationState<Args, Data> => {\n\tconst [data, setData] = createSignal<Data | null>(null);\n\tconst [error, setError] = createSignal<AuthClientError | null>(null);\n\tconst [isPending, setIsPending] = createSignal(false);\n\tlet alive = true;\n\tonCleanup(() => {\n\t\talive = false;\n\t});\n\n\tconst mutate: Mutator<Args, Data> = async (args) => {\n\t\tsetIsPending(true);\n\t\tsetError(null);\n\t\tconst result = await run(args);\n\t\tif (alive) {\n\t\t\t// Solid's setter accepts a value or a setter-fn; the fn-form keeps Data | null\n\t\t\t// passing through without narrowing the writable signal's value type.\n\t\t\tsetData(() => result.data);\n\t\t\tsetError(result.error);\n\t\t\tsetIsPending(false);\n\t\t}\n\n\t\treturn result;\n\t};\n\n\tconst reset = () => {\n\t\tsetData(() => null);\n\t\tsetError(null);\n\t\tsetIsPending(false);\n\t};\n\n\treturn { data, error, isPending, mutate, reset };\n};\n\nexport const useMagicLink = (client: AuthClient) =>\n\tuseMutation(client.passwordless.requestMagicLink);\n\nexport const useMfaChallenge = (client: AuthClient) =>\n\tuseMutation(client.mfa.challenge);\n\nexport const usePasswordReset = (client: AuthClient) =>\n\tuseMutation(client.passwordReset.request);\n\n// Query composable for the user's active sessions; refetch() reruns it, revoke(sessionId)\n// kills one and refetches. Same `{ data, error, isPending }` triplet as the mutations so\n// the consumer can render one way.\nexport const useSessions = (client: AuthClient) => {\n\tconst [data, setData] = createSignal<unknown[] | null>(null);\n\tconst [error, setError] = createSignal<AuthClientError | null>(null);\n\tconst [isPending, setIsPending] = createSignal(true);\n\tlet alive = true;\n\tonCleanup(() => {\n\t\talive = false;\n\t});\n\n\tconst refetch = async () => {\n\t\tsetIsPending(true);\n\t\tconst result = await client.sessions.list();\n\t\tif (alive) {\n\t\t\tsetData(() => result.data);\n\t\t\tsetError(result.error);\n\t\t\tsetIsPending(false);\n\t\t}\n\t};\n\n\tconst revoke = async (sessionId: string) => {\n\t\tconst result = await client.sessions.revoke(sessionId);\n\t\tif (result.error === null) await refetch();\n\n\t\treturn result;\n\t};\n\n\tvoid refetch();\n\n\treturn { data, error, isPending, refetch, revoke };\n};\n\nexport const useSignIn = (client: AuthClient) =>\n\tuseMutation(client.signIn.email);\n\nexport const useSignOut = (client: AuthClient) => useMutation(client.signOut);\n\nexport const useSignUp = (client: AuthClient) =>\n\tuseMutation(client.signUp.email);\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;AAIA;AAiBA,IAAM,cAAc,CACnB,QAC+B;AAAA,EAC/B,OAAO,MAAM,WAAW,aAA0B,IAAI;AAAA,EACtD,OAAO,OAAO,YAAY,aAAqC,IAAI;AAAA,EACnE,OAAO,WAAW,gBAAgB,aAAa,KAAK;AAAA,EACpD,IAAI,QAAQ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M,OAAO,SAAS,OAAO,SAAS;AAAA,IACrD,IAAI,OAAO,UAAU;AAAA,MAAM,MAAM,QAAQ;AAAA,IAEzC,OAAO;AAAA;AAAA,EAGH,QAAQ;AAAA,EAEb,OAAO,EAAE,MAAM,OAAO,WAAW,SAAS,OAAO;AAAA;AAG3C,IAAM,YAAY,CAAC,WACzB,YAAY,OAAO,OAAO,KAAK;AAEzB,IAAM,aAAa,CAAC,WAAuB,YAAY,OAAO,OAAO;AAErE,IAAM,YAAY,CAAC,WACzB,YAAY,OAAO,OAAO,KAAK;",
|
|
8
|
+
"debugId": "C75839665B18FF0264756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type Writable } from 'svelte/store';
|
|
2
|
+
import type { AuthClient, AuthClientError } from './createAuthClient';
|
|
3
|
+
type Mutator<Args, Data> = (args: Args) => Promise<{
|
|
4
|
+
data: Data | null;
|
|
5
|
+
error: AuthClientError | null;
|
|
6
|
+
}>;
|
|
7
|
+
type MutationState<Args, Data> = {
|
|
8
|
+
data: Writable<Data | null>;
|
|
9
|
+
error: Writable<AuthClientError | null>;
|
|
10
|
+
isPending: Writable<boolean>;
|
|
11
|
+
mutate: Mutator<Args, Data>;
|
|
12
|
+
reset: () => void;
|
|
13
|
+
};
|
|
14
|
+
export declare const useMagicLink: (client: AuthClient) => MutationState<{
|
|
15
|
+
email: string;
|
|
16
|
+
}, {
|
|
17
|
+
ok: true;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const useMfaChallenge: (client: AuthClient) => MutationState<{
|
|
20
|
+
code: string;
|
|
21
|
+
}, {
|
|
22
|
+
status: "authenticated";
|
|
23
|
+
}>;
|
|
24
|
+
export declare const usePasswordReset: (client: AuthClient) => MutationState<{
|
|
25
|
+
email: string;
|
|
26
|
+
}, {
|
|
27
|
+
ok: true;
|
|
28
|
+
}>;
|
|
29
|
+
export declare const useSessions: (client: AuthClient) => {
|
|
30
|
+
data: Writable<unknown[] | null>;
|
|
31
|
+
error: Writable<AuthClientError | null>;
|
|
32
|
+
isPending: Writable<boolean>;
|
|
33
|
+
refetch: () => Promise<void>;
|
|
34
|
+
revoke: (sessionId: string) => Promise<{
|
|
35
|
+
data: null;
|
|
36
|
+
error: AuthClientError;
|
|
37
|
+
} | {
|
|
38
|
+
data: {
|
|
39
|
+
ok: true;
|
|
40
|
+
};
|
|
41
|
+
error: null;
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
44
|
+
export declare const useSignIn: (client: AuthClient) => MutationState<{
|
|
45
|
+
email: string;
|
|
46
|
+
password: string;
|
|
47
|
+
}, {
|
|
48
|
+
passwordCompromised?: boolean;
|
|
49
|
+
status: "authenticated" | "mfa_required";
|
|
50
|
+
}>;
|
|
51
|
+
export declare const useSignOut: (client: AuthClient) => MutationState<unknown, {
|
|
52
|
+
ok: true;
|
|
53
|
+
}>;
|
|
54
|
+
export declare const useSignUp: (client: AuthClient) => MutationState<{
|
|
55
|
+
[extra: string]: unknown;
|
|
56
|
+
email: string;
|
|
57
|
+
password: string;
|
|
58
|
+
}, {
|
|
59
|
+
status: "authenticated";
|
|
60
|
+
} | {
|
|
61
|
+
status: "verification_required";
|
|
62
|
+
}>;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/client/svelte.ts
|
|
3
|
+
import { writable } from "svelte/store";
|
|
4
|
+
var useMutation = (run) => {
|
|
5
|
+
const data = writable(null);
|
|
6
|
+
const error = writable(null);
|
|
7
|
+
const isPending = writable(false);
|
|
8
|
+
const mutate = async (args) => {
|
|
9
|
+
isPending.set(true);
|
|
10
|
+
error.set(null);
|
|
11
|
+
const result = await run(args);
|
|
12
|
+
data.set(result.data);
|
|
13
|
+
error.set(result.error);
|
|
14
|
+
isPending.set(false);
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
17
|
+
const reset = () => {
|
|
18
|
+
data.set(null);
|
|
19
|
+
error.set(null);
|
|
20
|
+
isPending.set(false);
|
|
21
|
+
};
|
|
22
|
+
return { data, error, isPending, mutate, reset };
|
|
23
|
+
};
|
|
24
|
+
var useMagicLink = (client) => useMutation(client.passwordless.requestMagicLink);
|
|
25
|
+
var useMfaChallenge = (client) => useMutation(client.mfa.challenge);
|
|
26
|
+
var usePasswordReset = (client) => useMutation(client.passwordReset.request);
|
|
27
|
+
var useSessions = (client) => {
|
|
28
|
+
const data = writable(null);
|
|
29
|
+
const error = writable(null);
|
|
30
|
+
const isPending = writable(true);
|
|
31
|
+
const refetch = async () => {
|
|
32
|
+
isPending.set(true);
|
|
33
|
+
const result = await client.sessions.list();
|
|
34
|
+
data.set(result.data);
|
|
35
|
+
error.set(result.error);
|
|
36
|
+
isPending.set(false);
|
|
37
|
+
};
|
|
38
|
+
const revoke = async (sessionId) => {
|
|
39
|
+
const result = await client.sessions.revoke(sessionId);
|
|
40
|
+
if (result.error === null)
|
|
41
|
+
await refetch();
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
refetch();
|
|
45
|
+
return { data, error, isPending, refetch, revoke };
|
|
46
|
+
};
|
|
47
|
+
var useSignIn = (client) => useMutation(client.signIn.email);
|
|
48
|
+
var useSignOut = (client) => useMutation(client.signOut);
|
|
49
|
+
var useSignUp = (client) => useMutation(client.signUp.email);
|
|
50
|
+
export {
|
|
51
|
+
useSignUp,
|
|
52
|
+
useSignOut,
|
|
53
|
+
useSignIn,
|
|
54
|
+
useSessions,
|
|
55
|
+
usePasswordReset,
|
|
56
|
+
useMfaChallenge,
|
|
57
|
+
useMagicLink
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//# debugId=4A57E67D0678452364756E2164756E21
|
|
61
|
+
//# sourceMappingURL=svelte.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/client/svelte.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"// Thin Svelte composables over `createAuthClient`, mirroring `./react`. Same `{ data,\n// error, isPending, mutate, reset }` shape — only the reactivity is Svelte's (writable\n// stores from `svelte/store`, which work in both Svelte 4 with `$store` auto-subscription\n// and Svelte 5 with $state-based usage via `get(store)` or `$:` reactivity).\n// Bring your own form / UI; these are primitives.\n\nimport { writable, type Writable } from 'svelte/store';\nimport type { AuthClient, AuthClientError } from './createAuthClient';\n\ntype Mutator<Args, Data> = (\n\targs: Args\n) => Promise<{ data: Data | null; error: AuthClientError | null }>;\n\ntype MutationState<Args, Data> = {\n\tdata: Writable<Data | null>;\n\terror: Writable<AuthClientError | null>;\n\tisPending: Writable<boolean>;\n\tmutate: Mutator<Args, Data>;\n\treset: () => void;\n};\n\n// Generic mutation composable. The exported composables are 1-2 line specializations of\n// this — kept private so consumers depend on the named API, not this internal shape.\nconst useMutation = <Args, Data>(\n\trun: Mutator<Args, Data>\n): MutationState<Args, Data> => {\n\tconst data: Writable<Data | null> = writable(null);\n\tconst error: Writable<AuthClientError | null> = writable(null);\n\tconst isPending = writable(false);\n\n\tconst mutate: Mutator<Args, Data> = async (args) => {\n\t\tisPending.set(true);\n\t\terror.set(null);\n\t\tconst result = await run(args);\n\t\tdata.set(result.data);\n\t\terror.set(result.error);\n\t\tisPending.set(false);\n\n\t\treturn result;\n\t};\n\n\tconst reset = () => {\n\t\tdata.set(null);\n\t\terror.set(null);\n\t\tisPending.set(false);\n\t};\n\n\treturn { data, error, isPending, mutate, reset };\n};\n\nexport const useMagicLink = (client: AuthClient) =>\n\tuseMutation(client.passwordless.requestMagicLink);\n\nexport const useMfaChallenge = (client: AuthClient) =>\n\tuseMutation(client.mfa.challenge);\n\nexport const usePasswordReset = (client: AuthClient) =>\n\tuseMutation(client.passwordReset.request);\n\n// Query composable for the user's active sessions; refetch() reruns it, revoke(sessionId)\n// kills one and refetches. Same `{ data, error, isPending }` triplet as the mutations so\n// the consumer can render one way.\nexport const useSessions = (client: AuthClient) => {\n\tconst data: Writable<unknown[] | null> = writable(null);\n\tconst error: Writable<AuthClientError | null> = writable(null);\n\tconst isPending = writable(true);\n\n\tconst refetch = async () => {\n\t\tisPending.set(true);\n\t\tconst result = await client.sessions.list();\n\t\tdata.set(result.data);\n\t\terror.set(result.error);\n\t\tisPending.set(false);\n\t};\n\n\tconst revoke = async (sessionId: string) => {\n\t\tconst result = await client.sessions.revoke(sessionId);\n\t\tif (result.error === null) await refetch();\n\n\t\treturn result;\n\t};\n\n\tvoid refetch();\n\n\treturn { data, error, isPending, refetch, revoke };\n};\n\nexport const useSignIn = (client: AuthClient) =>\n\tuseMutation(client.signIn.email);\n\nexport const useSignOut = (client: AuthClient) => useMutation(client.signOut);\n\nexport const useSignUp = (client: AuthClient) =>\n\tuseMutation(client.signUp.email);\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;AAMA;AAiBA,IAAM,cAAc,CACnB,QAC+B;AAAA,EAC/B,MAAM,OAA8B,SAAS,IAAI;AAAA,EACjD,MAAM,QAA0C,SAAS,IAAI;AAAA,EAC7D,MAAM,YAAY,SAAS,KAAK;AAAA,EAEhC,MAAM,SAA8B,OAAO,SAAS;AAAA,IACnD,UAAU,IAAI,IAAI;AAAA,IAClB,MAAM,IAAI,IAAI;AAAA,IACd,MAAM,SAAS,MAAM,IAAI,IAAI;AAAA,IAC7B,KAAK,IAAI,OAAO,IAAI;AAAA,IACpB,MAAM,IAAI,OAAO,KAAK;AAAA,IACtB,UAAU,IAAI,KAAK;AAAA,IAEnB,OAAO;AAAA;AAAA,EAGR,MAAM,QAAQ,MAAM;AAAA,IACnB,KAAK,IAAI,IAAI;AAAA,IACb,MAAM,IAAI,IAAI;AAAA,IACd,UAAU,IAAI,KAAK;AAAA;AAAA,EAGpB,OAAO,EAAE,MAAM,OAAO,WAAW,QAAQ,MAAM;AAAA;AAGzC,IAAM,eAAe,CAAC,WAC5B,YAAY,OAAO,aAAa,gBAAgB;AAE1C,IAAM,kBAAkB,CAAC,WAC/B,YAAY,OAAO,IAAI,SAAS;AAE1B,IAAM,mBAAmB,CAAC,WAChC,YAAY,OAAO,cAAc,OAAO;AAKlC,IAAM,cAAc,CAAC,WAAuB;AAAA,EAClD,MAAM,OAAmC,SAAS,IAAI;AAAA,EACtD,MAAM,QAA0C,SAAS,IAAI;AAAA,EAC7D,MAAM,YAAY,SAAS,IAAI;AAAA,EAE/B,MAAM,UAAU,YAAY;AAAA,IAC3B,UAAU,IAAI,IAAI;AAAA,IAClB,MAAM,SAAS,MAAM,OAAO,SAAS,KAAK;AAAA,IAC1C,KAAK,IAAI,OAAO,IAAI;AAAA,IACpB,MAAM,IAAI,OAAO,KAAK;AAAA,IACtB,UAAU,IAAI,KAAK;AAAA;AAAA,EAGpB,MAAM,SAAS,OAAO,cAAsB;AAAA,IAC3C,MAAM,SAAS,MAAM,OAAO,SAAS,OAAO,SAAS;AAAA,IACrD,IAAI,OAAO,UAAU;AAAA,MAAM,MAAM,QAAQ;AAAA,IAEzC,OAAO;AAAA;AAAA,EAGH,QAAQ;AAAA,EAEb,OAAO,EAAE,MAAM,OAAO,WAAW,SAAS,OAAO;AAAA;AAG3C,IAAM,YAAY,CAAC,WACzB,YAAY,OAAO,OAAO,KAAK;AAEzB,IAAM,aAAa,CAAC,WAAuB,YAAY,OAAO,OAAO;AAErE,IAAM,YAAY,CAAC,WACzB,YAAY,OAAO,OAAO,KAAK;",
|
|
8
|
+
"debugId": "4A57E67D0678452364756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type Ref } from 'vue';
|
|
2
|
+
import type { AuthClient, AuthClientError } from './createAuthClient';
|
|
3
|
+
type Mutator<Args, Data> = (args: Args) => Promise<{
|
|
4
|
+
data: Data | null;
|
|
5
|
+
error: AuthClientError | null;
|
|
6
|
+
}>;
|
|
7
|
+
type MutationState<Args, Data> = {
|
|
8
|
+
data: Ref<Data | null>;
|
|
9
|
+
error: Ref<AuthClientError | null>;
|
|
10
|
+
isPending: Ref<boolean>;
|
|
11
|
+
mutate: Mutator<Args, Data>;
|
|
12
|
+
reset: () => void;
|
|
13
|
+
};
|
|
14
|
+
export declare const useMagicLink: (client: AuthClient) => MutationState<{
|
|
15
|
+
email: string;
|
|
16
|
+
}, {
|
|
17
|
+
ok: true;
|
|
18
|
+
}>;
|
|
19
|
+
export declare const useMfaChallenge: (client: AuthClient) => MutationState<{
|
|
20
|
+
code: string;
|
|
21
|
+
}, {
|
|
22
|
+
status: "authenticated";
|
|
23
|
+
}>;
|
|
24
|
+
export declare const usePasswordReset: (client: AuthClient) => MutationState<{
|
|
25
|
+
email: string;
|
|
26
|
+
}, {
|
|
27
|
+
ok: true;
|
|
28
|
+
}>;
|
|
29
|
+
export declare const useSessions: (client: AuthClient) => {
|
|
30
|
+
data: Ref<unknown[] | null, unknown[] | null>;
|
|
31
|
+
error: Ref<AuthClientError | null, AuthClientError | null>;
|
|
32
|
+
isPending: Ref<boolean, boolean>;
|
|
33
|
+
refetch: () => Promise<void>;
|
|
34
|
+
revoke: (sessionId: string) => Promise<{
|
|
35
|
+
data: null;
|
|
36
|
+
error: AuthClientError;
|
|
37
|
+
} | {
|
|
38
|
+
data: {
|
|
39
|
+
ok: true;
|
|
40
|
+
};
|
|
41
|
+
error: null;
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
44
|
+
export declare const useSignIn: (client: AuthClient) => MutationState<{
|
|
45
|
+
email: string;
|
|
46
|
+
password: string;
|
|
47
|
+
}, {
|
|
48
|
+
passwordCompromised?: boolean;
|
|
49
|
+
status: "authenticated" | "mfa_required";
|
|
50
|
+
}>;
|
|
51
|
+
export declare const useSignOut: (client: AuthClient) => MutationState<unknown, {
|
|
52
|
+
ok: true;
|
|
53
|
+
}>;
|
|
54
|
+
export declare const useSignUp: (client: AuthClient) => MutationState<{
|
|
55
|
+
[extra: string]: unknown;
|
|
56
|
+
email: string;
|
|
57
|
+
password: string;
|
|
58
|
+
}, {
|
|
59
|
+
status: "authenticated";
|
|
60
|
+
} | {
|
|
61
|
+
status: "verification_required";
|
|
62
|
+
}>;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/client/vue.ts
|
|
3
|
+
import { onScopeDispose, ref } from "vue";
|
|
4
|
+
var useMutation = (run) => {
|
|
5
|
+
const data = ref(null);
|
|
6
|
+
const error = ref(null);
|
|
7
|
+
const isPending = ref(false);
|
|
8
|
+
let alive = true;
|
|
9
|
+
onScopeDispose(() => {
|
|
10
|
+
alive = false;
|
|
11
|
+
});
|
|
12
|
+
const mutate = async (args) => {
|
|
13
|
+
isPending.value = true;
|
|
14
|
+
error.value = null;
|
|
15
|
+
const result = await run(args);
|
|
16
|
+
if (alive) {
|
|
17
|
+
data.value = result.data;
|
|
18
|
+
error.value = result.error;
|
|
19
|
+
isPending.value = false;
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
const reset = () => {
|
|
24
|
+
data.value = null;
|
|
25
|
+
error.value = null;
|
|
26
|
+
isPending.value = false;
|
|
27
|
+
};
|
|
28
|
+
return { data, error, isPending, mutate, reset };
|
|
29
|
+
};
|
|
30
|
+
var useMagicLink = (client) => useMutation(client.passwordless.requestMagicLink);
|
|
31
|
+
var useMfaChallenge = (client) => useMutation(client.mfa.challenge);
|
|
32
|
+
var usePasswordReset = (client) => useMutation(client.passwordReset.request);
|
|
33
|
+
var useSessions = (client) => {
|
|
34
|
+
const data = ref(null);
|
|
35
|
+
const error = ref(null);
|
|
36
|
+
const isPending = ref(true);
|
|
37
|
+
let alive = true;
|
|
38
|
+
onScopeDispose(() => {
|
|
39
|
+
alive = false;
|
|
40
|
+
});
|
|
41
|
+
const refetch = async () => {
|
|
42
|
+
isPending.value = true;
|
|
43
|
+
const result = await client.sessions.list();
|
|
44
|
+
if (alive) {
|
|
45
|
+
data.value = result.data;
|
|
46
|
+
error.value = result.error;
|
|
47
|
+
isPending.value = false;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const revoke = async (sessionId) => {
|
|
51
|
+
const result = await client.sessions.revoke(sessionId);
|
|
52
|
+
if (result.error === null)
|
|
53
|
+
await refetch();
|
|
54
|
+
return result;
|
|
55
|
+
};
|
|
56
|
+
refetch();
|
|
57
|
+
return { data, error, isPending, refetch, revoke };
|
|
58
|
+
};
|
|
59
|
+
var useSignIn = (client) => useMutation(client.signIn.email);
|
|
60
|
+
var useSignOut = (client) => useMutation(client.signOut);
|
|
61
|
+
var useSignUp = (client) => useMutation(client.signUp.email);
|
|
62
|
+
export {
|
|
63
|
+
useSignUp,
|
|
64
|
+
useSignOut,
|
|
65
|
+
useSignIn,
|
|
66
|
+
useSessions,
|
|
67
|
+
usePasswordReset,
|
|
68
|
+
useMfaChallenge,
|
|
69
|
+
useMagicLink
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//# debugId=3BD102183F34B9F664756E2164756E21
|
|
73
|
+
//# sourceMappingURL=vue.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/client/vue.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"// Thin Vue composables over `createAuthClient`, mirroring `./react`. Same `{ data, error,\n// isPending, mutate, reset }` shape — only the reactivity is Vue's (refs + onScopeDispose).\n// Bring your own form / UI; these are primitives.\n\nimport { onScopeDispose, ref, type Ref } from 'vue';\nimport type { AuthClient, AuthClientError } from './createAuthClient';\n\ntype Mutator<Args, Data> = (\n\targs: Args\n) => Promise<{ data: Data | null; error: AuthClientError | null }>;\n\ntype MutationState<Args, Data> = {\n\tdata: Ref<Data | null>;\n\terror: Ref<AuthClientError | null>;\n\tisPending: Ref<boolean>;\n\tmutate: Mutator<Args, Data>;\n\treset: () => void;\n};\n\n// Generic mutation composable. The exported composables are 1-2 line specializations of\n// this — kept private so consumers depend on the named API, not this internal shape.\nconst useMutation = <Args, Data>(\n\trun: Mutator<Args, Data>\n): MutationState<Args, Data> => {\n\tconst data: Ref<Data | null> = ref(null);\n\tconst error: Ref<AuthClientError | null> = ref(null);\n\tconst isPending = ref(false);\n\tlet alive = true;\n\tonScopeDispose(() => {\n\t\talive = false;\n\t});\n\n\tconst mutate: Mutator<Args, Data> = async (args) => {\n\t\tisPending.value = true;\n\t\terror.value = null;\n\t\tconst result = await run(args);\n\t\tif (alive) {\n\t\t\tdata.value = result.data;\n\t\t\terror.value = result.error;\n\t\t\tisPending.value = false;\n\t\t}\n\n\t\treturn result;\n\t};\n\n\tconst reset = () => {\n\t\tdata.value = null;\n\t\terror.value = null;\n\t\tisPending.value = false;\n\t};\n\n\treturn { data, error, isPending, mutate, reset };\n};\n\nexport const useMagicLink = (client: AuthClient) =>\n\tuseMutation(client.passwordless.requestMagicLink);\n\nexport const useMfaChallenge = (client: AuthClient) =>\n\tuseMutation(client.mfa.challenge);\n\nexport const usePasswordReset = (client: AuthClient) =>\n\tuseMutation(client.passwordReset.request);\n\n// Query composable for the user's active sessions; refetch() reruns it, revoke(sessionId)\n// kills one and refetches. Same `{ data, error, isPending }` triplet as the mutations so\n// the consumer can render one way.\nexport const useSessions = (client: AuthClient) => {\n\tconst data: Ref<unknown[] | null> = ref(null);\n\tconst error: Ref<AuthClientError | null> = ref(null);\n\tconst isPending = ref(true);\n\tlet alive = true;\n\tonScopeDispose(() => {\n\t\talive = false;\n\t});\n\n\tconst refetch = async () => {\n\t\tisPending.value = true;\n\t\tconst result = await client.sessions.list();\n\t\tif (alive) {\n\t\t\tdata.value = result.data;\n\t\t\terror.value = result.error;\n\t\t\tisPending.value = false;\n\t\t}\n\t};\n\n\tconst revoke = async (sessionId: string) => {\n\t\tconst result = await client.sessions.revoke(sessionId);\n\t\tif (result.error === null) await refetch();\n\n\t\treturn result;\n\t};\n\n\tvoid refetch();\n\n\treturn { data, error, isPending, refetch, revoke };\n};\n\nexport const useSignIn = (client: AuthClient) =>\n\tuseMutation(client.signIn.email);\n\nexport const useSignOut = (client: AuthClient) => useMut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AQ;AAAA,IAClB,MAAM,SAAS,MAAM,OAAO,SAAS,KAAK;AAAA,IAC1C,IAAI,OAAO;AAAA,MACV,KAAK,QAAQ,OAAO;AAAA,MACpB,MAAM,QAAQ,OAAO;AAAA,MACrB,UAAU,QAAQ;AAAA,IACnB;AAAA;AAAA,EAGD,MAAM,SAAS,OAAO,cAAsB;AAAA,IAC3C,MAAM,SAAS,MAAM,OAAO,SAAS,OAAO,SAAS;AAAA,IACrD,IAAI,OAAO,UAAU;AAAA,MAAM,MAAM,QAAQ;AAAA,IAEzC,OAAO;AAAA;AAAA,EAGH,QAAQ;AAAA,EAEb,OAAO,EAAE,MAAM,OAAO,WAAW,SAAS,OAAO;AAAA;AAG3C,IAAM,YAAY,CAAC,WACzB,YAAY,OAAO,OAAO,KAAK;AAEzB,IAAM,aAAa,CAAC,WAAuB,YAAY,OAAO,OAAO;AAErE,IAAM,YAAY,CAAC,WACzB,YAAY,OAAO,OAAO,KAAK;",
|
|
8
|
+
"debugId": "3BD102183F34B9F664756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -12453,7 +12453,7 @@ export declare const auth: <UserType>({ providersConfiguration, authorizeRoute,
|
|
|
12453
12453
|
headers: unknown;
|
|
12454
12454
|
response: {
|
|
12455
12455
|
400: "Cookies are missing";
|
|
12456
|
-
401: "No
|
|
12456
|
+
401: "No user session id found";
|
|
12457
12457
|
200: Response;
|
|
12458
12458
|
422: {
|
|
12459
12459
|
type: "validation";
|
package/dist/index.js
CHANGED
|
@@ -7891,12 +7891,9 @@ var signout = ({
|
|
|
7891
7891
|
store: { session },
|
|
7892
7892
|
cookie: { user_session_id, auth_provider }
|
|
7893
7893
|
}) => {
|
|
7894
|
-
if (
|
|
7894
|
+
if (user_session_id === undefined) {
|
|
7895
7895
|
return status("Bad Request", "Cookies are missing");
|
|
7896
7896
|
}
|
|
7897
|
-
if (auth_provider.value === undefined) {
|
|
7898
|
-
return status("Unauthorized", "No auth provider found");
|
|
7899
|
-
}
|
|
7900
7897
|
if (user_session_id.value === undefined) {
|
|
7901
7898
|
return status("Unauthorized", "No user session id found");
|
|
7902
7899
|
}
|
|
@@ -7908,7 +7905,7 @@ var signout = ({
|
|
|
7908
7905
|
const currentSession = signoutSession[user_session_id.value];
|
|
7909
7906
|
if (currentSession !== undefined) {
|
|
7910
7907
|
const signedOut = await runSignOut(onSignOut, {
|
|
7911
|
-
authProvider: auth_provider
|
|
7908
|
+
authProvider: auth_provider?.value,
|
|
7912
7909
|
session: signoutSession,
|
|
7913
7910
|
userSessionId: user_session_id.value
|
|
7914
7911
|
});
|
|
@@ -7925,7 +7922,7 @@ var signout = ({
|
|
|
7925
7922
|
delete session[user_session_id.value];
|
|
7926
7923
|
}
|
|
7927
7924
|
user_session_id.remove();
|
|
7928
|
-
auth_provider
|
|
7925
|
+
auth_provider?.remove();
|
|
7929
7926
|
return new Response(null, { status: 204 });
|
|
7930
7927
|
}, {
|
|
7931
7928
|
cookie: t24.Cookie({
|
|
@@ -23904,5 +23901,5 @@ export {
|
|
|
23904
23901
|
AuthIdentityConflictError
|
|
23905
23902
|
};
|
|
23906
23903
|
|
|
23907
|
-
//# debugId=
|
|
23904
|
+
//# debugId=334E206D4FA9C2DF64756E2164756E21
|
|
23908
23905
|
//# sourceMappingURL=index.js.map
|