@witchcraft/nuxt-auth 0.3.1 → 0.4.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/module.json +2 -2
- package/dist/module.mjs +1 -1
- package/dist/runtime/components/UserRegistration.d.vue.ts +16 -6
- package/dist/runtime/components/UserRegistration.vue +60 -35
- package/dist/runtime/components/UserRegistration.vue.d.ts +16 -6
- package/dist/runtime/server/utils/Auth.js +1 -0
- package/dist/runtime/types.js +1 -1
- package/package.json +10 -9
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import z from "zod";
|
|
1
2
|
import { type Ref } from "#imports";
|
|
2
3
|
type __VLS_Props = {
|
|
3
4
|
debounce?: number;
|
|
@@ -5,26 +6,35 @@ type __VLS_Props = {
|
|
|
5
6
|
getValidUsernameRoute?: (username: string) => string;
|
|
6
7
|
onSubmitRegistration?: (event: Event, username: string, error: Ref<string>, redirectUrl: string, deeplink?: string) => void;
|
|
7
8
|
id?: string;
|
|
9
|
+
/**
|
|
10
|
+
* When a validator is provided, if it errors, the server is not queried so as to avoid invalid queries. Any errors it produces are also shown.
|
|
11
|
+
*
|
|
12
|
+
* @default defaultZodUsernameSchema
|
|
13
|
+
*/
|
|
14
|
+
usernameSchema?: z.ZodType<string, any, any>;
|
|
8
15
|
};
|
|
9
|
-
declare var
|
|
16
|
+
declare var __VLS_12: {}, __VLS_19: {}, __VLS_26: {}, __VLS_33: {}, __VLS_41: {
|
|
10
17
|
error: import("nuxt/app").NuxtError<unknown> | undefined;
|
|
11
18
|
registrationError: string;
|
|
19
|
+
localUsernameError: string | undefined;
|
|
20
|
+
id: string;
|
|
12
21
|
};
|
|
13
22
|
type __VLS_Slots = {} & {
|
|
14
|
-
'username-icon-loading'?: (props: typeof
|
|
23
|
+
'username-icon-loading'?: (props: typeof __VLS_12) => any;
|
|
15
24
|
} & {
|
|
16
|
-
'username-icon-valid'?: (props: typeof
|
|
25
|
+
'username-icon-valid'?: (props: typeof __VLS_19) => any;
|
|
17
26
|
} & {
|
|
18
|
-
'username-icon-invalid'?: (props: typeof
|
|
27
|
+
'username-icon-invalid'?: (props: typeof __VLS_26) => any;
|
|
19
28
|
} & {
|
|
20
|
-
default?: (props: typeof
|
|
29
|
+
default?: (props: typeof __VLS_33) => any;
|
|
21
30
|
} & {
|
|
22
|
-
error?: (props: typeof
|
|
31
|
+
error?: (props: typeof __VLS_41) => any;
|
|
23
32
|
};
|
|
24
33
|
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
25
34
|
debounce: number;
|
|
26
35
|
getValidUsernameRoute: (username: string) => string;
|
|
27
36
|
onSubmitRegistration: (event: Event, username: string, error: Ref<string>, redirectUrl: string, deeplink?: string) => void;
|
|
37
|
+
usernameSchema: z.ZodType<string, any, any>;
|
|
28
38
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
29
39
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
30
40
|
declare const _default: typeof __VLS_export;
|
|
@@ -12,22 +12,30 @@
|
|
|
12
12
|
"
|
|
13
13
|
@submit.prevent="handleSubmit"
|
|
14
14
|
>
|
|
15
|
-
<div class="flex flex-col">
|
|
16
|
-
<
|
|
15
|
+
<div class="flex flex-col items-stretch">
|
|
16
|
+
<label
|
|
17
17
|
:for="usernameId"
|
|
18
|
+
class="text-sm"
|
|
18
19
|
>
|
|
19
20
|
Username
|
|
20
|
-
</
|
|
21
|
+
</label>
|
|
21
22
|
<div>
|
|
22
|
-
<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
<div class="input-wrapper relative flex">
|
|
24
|
+
<WSimpleInput
|
|
25
|
+
:id="usernameId"
|
|
26
|
+
:aria-busy="isLoading"
|
|
27
|
+
:aria-describedby="`${usernameId}-error`"
|
|
28
|
+
name="username"
|
|
29
|
+
class="w-0 pr-[calc(1rem+var(--spacing)*2)]"
|
|
30
|
+
:valid="!anyError && (username === '' || isValidUsername)"
|
|
31
|
+
:aria-invalid="!!anyError || !isValidUsername && username !== ''"
|
|
32
|
+
v-model="username"
|
|
33
|
+
/>
|
|
34
|
+
<div
|
|
35
|
+
class="absolute top-0 bottom-0 pr-1 right-0"
|
|
36
|
+
aria-live="polite"
|
|
37
|
+
>
|
|
38
|
+
<WIcon class="w-[1rem] pointer-events-none mt-px">
|
|
31
39
|
<slot
|
|
32
40
|
v-if="isLoading"
|
|
33
41
|
name="username-icon-loading"
|
|
@@ -35,14 +43,16 @@
|
|
|
35
43
|
<IconSpinner
|
|
36
44
|
class="animate-spin text-neutral-500"
|
|
37
45
|
/>
|
|
46
|
+
<span class="sr-only">Checking availability...</span>
|
|
38
47
|
</slot>
|
|
39
48
|
<slot
|
|
40
49
|
v-else-if="isValidUsername"
|
|
41
50
|
name="username-icon-valid"
|
|
42
51
|
>
|
|
43
52
|
<IconCheck
|
|
44
|
-
class="text-green-500"
|
|
53
|
+
class="text-green-500 scale-110"
|
|
45
54
|
/>
|
|
55
|
+
<span class="sr-only">Username available.</span>
|
|
46
56
|
</slot>
|
|
47
57
|
<slot
|
|
48
58
|
v-else-if="anyError || !isValidUsername && username !== ''"
|
|
@@ -51,10 +61,11 @@
|
|
|
51
61
|
<IconInvalid
|
|
52
62
|
class="text-red-500"
|
|
53
63
|
/>
|
|
64
|
+
<span class="sr-only">Username unavailable.</span>
|
|
54
65
|
</slot>
|
|
55
66
|
</WIcon>
|
|
56
|
-
</
|
|
57
|
-
</
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
58
69
|
</div>
|
|
59
70
|
</div>
|
|
60
71
|
<slot/>
|
|
@@ -69,22 +80,23 @@
|
|
|
69
80
|
<slot
|
|
70
81
|
v-if="anyError"
|
|
71
82
|
name="error"
|
|
72
|
-
v-bind="{ error, registrationError }"
|
|
83
|
+
v-bind="{ error, registrationError, localUsernameError, id: `${usernameId}-error` }"
|
|
73
84
|
>
|
|
74
85
|
<div
|
|
86
|
+
:id="`${usernameId}-error`"
|
|
75
87
|
class="
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
border
|
|
89
|
+
border-red-500
|
|
90
|
+
rounded-md
|
|
91
|
+
p-2
|
|
92
|
+
text-red-500
|
|
93
|
+
bg-red-100
|
|
94
|
+
dark:bg-red-950/50
|
|
95
|
+
whitespace-pre-wrap
|
|
96
|
+
break-all
|
|
97
|
+
"
|
|
86
98
|
>
|
|
87
|
-
{{ registrationError || error }}
|
|
99
|
+
{{ localUsernameError || registrationError || error }}
|
|
88
100
|
</div>
|
|
89
101
|
</slot>
|
|
90
102
|
</form>
|
|
@@ -92,11 +104,12 @@
|
|
|
92
104
|
|
|
93
105
|
<script setup>
|
|
94
106
|
import { refDebounced } from "@vueuse/core";
|
|
107
|
+
import z from "zod";
|
|
95
108
|
import { navigateTo, useAsyncData, useRuntimeConfig } from "#app";
|
|
96
109
|
import { computed, ref, useId, useRoute } from "#imports";
|
|
97
|
-
import
|
|
98
|
-
import
|
|
99
|
-
import
|
|
110
|
+
import IconCheck from "~icons/lucide/check";
|
|
111
|
+
import IconSpinner from "~icons/lucide/loader-circle";
|
|
112
|
+
import IconInvalid from "~icons/lucide/x";
|
|
100
113
|
import { useAuth } from "../composables/useAuth.js";
|
|
101
114
|
import { AUTH_ERROR, defaultZodUsernameSchema } from "../types.js";
|
|
102
115
|
import { getAuthApiRoute } from "../utils/getAuthApiRoute.js";
|
|
@@ -127,23 +140,35 @@ const props = defineProps({
|
|
|
127
140
|
await navigateTo(res.redirectUrl, { external: true });
|
|
128
141
|
}
|
|
129
142
|
} },
|
|
130
|
-
id: { type: String, required: false }
|
|
143
|
+
id: { type: String, required: false },
|
|
144
|
+
usernameSchema: { type: null, required: false, default: defaultZodUsernameSchema }
|
|
131
145
|
});
|
|
132
146
|
const usernameId = props.id ?? useId();
|
|
133
147
|
const username = ref("");
|
|
134
148
|
const debouncedUsername = refDebounced(username, props.debounce);
|
|
135
149
|
const registrationError = ref("");
|
|
150
|
+
const localUsernameError = computed(() => {
|
|
151
|
+
const res = props.usernameSchema.safeParse(username.value);
|
|
152
|
+
if (res.success) return void 0;
|
|
153
|
+
return z.prettifyError(res.error).replaceAll("\u2716", "\u274C");
|
|
154
|
+
});
|
|
136
155
|
const { data: isValidUsername, status, error } = await useAsyncData(
|
|
137
156
|
"auth:username:valid",
|
|
138
|
-
() =>
|
|
157
|
+
async () => {
|
|
158
|
+
if (localUsernameError.value) return false;
|
|
159
|
+
return $fetch(props.getValidUsernameRoute(debouncedUsername.value));
|
|
160
|
+
},
|
|
139
161
|
{
|
|
140
|
-
watch: [debouncedUsername],
|
|
162
|
+
watch: [localUsernameError, debouncedUsername],
|
|
141
163
|
immediate: false,
|
|
142
164
|
default: () => false
|
|
143
165
|
}
|
|
144
166
|
);
|
|
145
|
-
const isLoading = computed(() =>
|
|
146
|
-
|
|
167
|
+
const isLoading = computed(() => {
|
|
168
|
+
if (localUsernameError.value) return false;
|
|
169
|
+
return username.value !== "" && (status.value === "pending" || username.value !== debouncedUsername.value);
|
|
170
|
+
});
|
|
171
|
+
const anyError = computed(() => localUsernameError.value || error.value || registrationError.value);
|
|
147
172
|
const deeplink = typeof query.deeplink === "string" ? query.deeplink : void 0;
|
|
148
173
|
const redirect = deeplink ? useRuntimeConfig().public.auth.authRoutes.externalCode : useRuntimeConfig().public.auth.authRoutes.register;
|
|
149
174
|
if (!redirect) throw new Error("No externalCode or register route defined.");
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import z from "zod";
|
|
1
2
|
import { type Ref } from "#imports";
|
|
2
3
|
type __VLS_Props = {
|
|
3
4
|
debounce?: number;
|
|
@@ -5,26 +6,35 @@ type __VLS_Props = {
|
|
|
5
6
|
getValidUsernameRoute?: (username: string) => string;
|
|
6
7
|
onSubmitRegistration?: (event: Event, username: string, error: Ref<string>, redirectUrl: string, deeplink?: string) => void;
|
|
7
8
|
id?: string;
|
|
9
|
+
/**
|
|
10
|
+
* When a validator is provided, if it errors, the server is not queried so as to avoid invalid queries. Any errors it produces are also shown.
|
|
11
|
+
*
|
|
12
|
+
* @default defaultZodUsernameSchema
|
|
13
|
+
*/
|
|
14
|
+
usernameSchema?: z.ZodType<string, any, any>;
|
|
8
15
|
};
|
|
9
|
-
declare var
|
|
16
|
+
declare var __VLS_12: {}, __VLS_19: {}, __VLS_26: {}, __VLS_33: {}, __VLS_41: {
|
|
10
17
|
error: import("nuxt/app").NuxtError<unknown> | undefined;
|
|
11
18
|
registrationError: string;
|
|
19
|
+
localUsernameError: string | undefined;
|
|
20
|
+
id: string;
|
|
12
21
|
};
|
|
13
22
|
type __VLS_Slots = {} & {
|
|
14
|
-
'username-icon-loading'?: (props: typeof
|
|
23
|
+
'username-icon-loading'?: (props: typeof __VLS_12) => any;
|
|
15
24
|
} & {
|
|
16
|
-
'username-icon-valid'?: (props: typeof
|
|
25
|
+
'username-icon-valid'?: (props: typeof __VLS_19) => any;
|
|
17
26
|
} & {
|
|
18
|
-
'username-icon-invalid'?: (props: typeof
|
|
27
|
+
'username-icon-invalid'?: (props: typeof __VLS_26) => any;
|
|
19
28
|
} & {
|
|
20
|
-
default?: (props: typeof
|
|
29
|
+
default?: (props: typeof __VLS_33) => any;
|
|
21
30
|
} & {
|
|
22
|
-
error?: (props: typeof
|
|
31
|
+
error?: (props: typeof __VLS_41) => any;
|
|
23
32
|
};
|
|
24
33
|
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
25
34
|
debounce: number;
|
|
26
35
|
getValidUsernameRoute: (username: string) => string;
|
|
27
36
|
onSubmitRegistration: (event: Event, username: string, error: Ref<string>, redirectUrl: string, deeplink?: string) => void;
|
|
37
|
+
usernameSchema: z.ZodType<string, any, any>;
|
|
28
38
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
29
39
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
30
40
|
declare const _default: typeof __VLS_export;
|
|
@@ -649,6 +649,7 @@ export class Auth {
|
|
|
649
649
|
}
|
|
650
650
|
async createAccessToken(userId, payload = {}) {
|
|
651
651
|
return signJwt({ ...payload, userId }, this.rc.authSecret, {
|
|
652
|
+
// ms is different package version so type doesn't match
|
|
652
653
|
expiresIn: this.externalAccessTokenExpiresIn
|
|
653
654
|
});
|
|
654
655
|
}
|
package/dist/runtime/types.js
CHANGED
|
@@ -16,7 +16,7 @@ export const zExternalCallbackPageQuery = z.object({
|
|
|
16
16
|
})
|
|
17
17
|
);
|
|
18
18
|
export const defaultZodUsernameSchema = z.string().min(3).max(32).regex(/^[\w.]+$/, "Username can only contain letters, numbers, underscores, and periods.");
|
|
19
|
-
export const providerStylesInjectionKey = Symbol("providerStyles");
|
|
19
|
+
export const providerStylesInjectionKey = Symbol.for("@witchcraft/nuxt-auth:providerStyles");
|
|
20
20
|
export const AUTH_ERROR = enumFromArray([
|
|
21
21
|
"USER_ALREADY_REGISTERED",
|
|
22
22
|
"UNKNOWN_PROVIDER",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@witchcraft/nuxt-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Nuxt module for logging.",
|
|
5
5
|
"repository": "witchcraftjs/nuxt-auth",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"drizzle-orm": "^0.
|
|
27
|
+
"drizzle-orm": "^0.45.2"
|
|
28
28
|
},
|
|
29
29
|
"@comments": {
|
|
30
30
|
"dependencies": {
|
|
@@ -41,16 +41,16 @@
|
|
|
41
41
|
"@types/jsonwebtoken": "^9.0.10",
|
|
42
42
|
"@vueuse/core": "^13.9.0",
|
|
43
43
|
"@witchcraft/nuxt-logger": "^0.0.11",
|
|
44
|
-
"@witchcraft/ui": "^0.
|
|
44
|
+
"@witchcraft/ui": "^0.5.0",
|
|
45
45
|
"arctic": "^3.7.0",
|
|
46
|
-
"cookie-es": "^
|
|
46
|
+
"cookie-es": "^3.1.1",
|
|
47
47
|
"defu": "^6.1.4",
|
|
48
48
|
"h3": "1.15.4",
|
|
49
49
|
"jsonwebtoken": "^9.0.2",
|
|
50
|
-
"ms": "^
|
|
50
|
+
"ms": "^3.0.0-canary.202508261828",
|
|
51
51
|
"nuxt-security": "^2.4.0",
|
|
52
|
-
"unplugin-icons": "^
|
|
53
|
-
"unplugin-vue-components": "^
|
|
52
|
+
"unplugin-icons": "^23.0.1",
|
|
53
|
+
"unplugin-vue-components": "^32.0.0",
|
|
54
54
|
"zod": "^4.1.12"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
@@ -65,16 +65,17 @@
|
|
|
65
65
|
"@types/node": "latest",
|
|
66
66
|
"changelogen": "^0.6.2",
|
|
67
67
|
"cross-env": "^10.1.0",
|
|
68
|
-
"drizzle-orm": "^0.
|
|
68
|
+
"drizzle-orm": "^0.45.2",
|
|
69
69
|
"electron": "^38.2.2",
|
|
70
70
|
"eslint": "^9.37.0",
|
|
71
71
|
"husky": "^9.1.7",
|
|
72
72
|
"nuxt": "^4.2.1",
|
|
73
73
|
"reka-ui": "^2.5.1",
|
|
74
|
+
"semantic-release": "^25.0.3",
|
|
74
75
|
"tailwindcss": "^4.1.14",
|
|
75
76
|
"typescript": "^5.9.3",
|
|
76
77
|
"vitest": "^3.2.4",
|
|
77
|
-
"vue-tsc": "^3.
|
|
78
|
+
"vue-tsc": "^3.3.3"
|
|
78
79
|
},
|
|
79
80
|
"release": {
|
|
80
81
|
"extends": [
|