nuxt-users 1.3.0 → 1.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/CHANGELOG.md +27 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/components/LoginForm.vue +51 -4
- package/dist/runtime/components/LoginForm.vue.d.ts +10 -1
- package/dist/runtime/plugin.js +18 -1
- package/package.json +1 -1
- package/dist/runtime/middleware/auth.global.d.ts +0 -2
- package/dist/runtime/middleware/auth.global.js +0 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## v1.4.0
|
|
5
|
+
|
|
6
|
+
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.3.0...v1.4.0)
|
|
7
|
+
|
|
8
|
+
### 🚀 Enhancements
|
|
9
|
+
|
|
10
|
+
- Implement forgot password closes #57 ([#57](https://github.com/rrd108/nuxt-users/issues/57))
|
|
11
|
+
|
|
12
|
+
### 🩹 Fixes
|
|
13
|
+
|
|
14
|
+
- Css color ([1d72336](https://github.com/rrd108/nuxt-users/commit/1d72336))
|
|
15
|
+
- Auth middleware ([113b165](https://github.com/rrd108/nuxt-users/commit/113b165))
|
|
16
|
+
- Enhances auth middleware and improves logging ([f519bbc](https://github.com/rrd108/nuxt-users/commit/f519bbc))
|
|
17
|
+
- Playground colors ([f87ade1](https://github.com/rrd108/nuxt-users/commit/f87ade1))
|
|
18
|
+
|
|
19
|
+
### 💅 Refactors
|
|
20
|
+
|
|
21
|
+
- Have a dedicated playground login page ([487d754](https://github.com/rrd108/nuxt-users/commit/487d754))
|
|
22
|
+
|
|
23
|
+
### 🏡 Chore
|
|
24
|
+
|
|
25
|
+
- **release:** V1.3.0 ([b127043](https://github.com/rrd108/nuxt-users/commit/b127043))
|
|
26
|
+
|
|
27
|
+
### ❤️ Contributors
|
|
28
|
+
|
|
29
|
+
- Rrd108 ([@rrd108](https://github.com/rrd108))
|
|
30
|
+
|
|
4
31
|
## v1.3.0
|
|
5
32
|
|
|
6
33
|
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.2.0...v1.3.0)
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -52,7 +52,7 @@ const module = defineNuxtModule({
|
|
|
52
52
|
passwordResetTokens: options.tables?.passwordResetTokens || defaultOptions.tables.passwordResetTokens
|
|
53
53
|
},
|
|
54
54
|
auth: {
|
|
55
|
-
whitelist:
|
|
55
|
+
whitelist: [...defaultOptions.auth?.whitelist || [], ...options.auth?.whitelist || []]
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
58
|
addPlugin({
|
|
@@ -3,11 +3,14 @@ import { ref } from "vue";
|
|
|
3
3
|
import { navigateTo } from "#app";
|
|
4
4
|
const props = defineProps({
|
|
5
5
|
apiEndpoint: { type: String, required: false, default: "/api/login" },
|
|
6
|
-
redirectTo: { type: String, required: false, default: "/" }
|
|
6
|
+
redirectTo: { type: String, required: false, default: "/" },
|
|
7
|
+
forgotPasswordEndpoint: { type: String, required: false, default: "/api/auth/forgot-password" }
|
|
7
8
|
});
|
|
8
|
-
const emit = defineEmits(["success", "error", "submit"]);
|
|
9
|
+
const emit = defineEmits(["success", "error", "forgot-password-error", "submit", "forgot-password-success"]);
|
|
9
10
|
const isLoading = ref(false);
|
|
11
|
+
const isForgotPasswordLoading = ref(false);
|
|
10
12
|
const error = ref("");
|
|
13
|
+
const forgotPasswordMessage = ref("");
|
|
11
14
|
const formData = ref({
|
|
12
15
|
email: "",
|
|
13
16
|
password: "",
|
|
@@ -37,6 +40,31 @@ const handleSubmit = async () => {
|
|
|
37
40
|
isLoading.value = false;
|
|
38
41
|
}
|
|
39
42
|
};
|
|
43
|
+
const handleForgotPassword = async () => {
|
|
44
|
+
if (!formData.value.email) {
|
|
45
|
+
error.value = "Please enter your email address first";
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
isForgotPasswordLoading.value = true;
|
|
49
|
+
forgotPasswordMessage.value = "";
|
|
50
|
+
error.value = "";
|
|
51
|
+
try {
|
|
52
|
+
const response = await $fetch(props.forgotPasswordEndpoint, {
|
|
53
|
+
method: "POST",
|
|
54
|
+
body: {
|
|
55
|
+
email: formData.value.email
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
forgotPasswordMessage.value = response.message;
|
|
59
|
+
emit("forgot-password-success");
|
|
60
|
+
} catch (err) {
|
|
61
|
+
const errorMessage = err && typeof err === "object" && "data" in err && err.data && typeof err.data === "object" && "statusMessage" in err.data ? String(err.data.statusMessage) : err instanceof Error ? err.message : "Failed to send password reset email";
|
|
62
|
+
error.value = errorMessage;
|
|
63
|
+
emit("forgot-password-error", errorMessage);
|
|
64
|
+
} finally {
|
|
65
|
+
isForgotPasswordLoading.value = false;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
40
68
|
</script>
|
|
41
69
|
|
|
42
70
|
<template>
|
|
@@ -119,13 +147,32 @@ const handleSubmit = async () => {
|
|
|
119
147
|
<a
|
|
120
148
|
href="#"
|
|
121
149
|
class="forgot-link"
|
|
150
|
+
:class="{ loading: isForgotPasswordLoading }"
|
|
151
|
+
@click.prevent="handleForgotPassword"
|
|
122
152
|
>
|
|
123
|
-
|
|
153
|
+
<span
|
|
154
|
+
v-if="isForgotPasswordLoading"
|
|
155
|
+
class="loading-spinner"
|
|
156
|
+
/>
|
|
157
|
+
{{ isForgotPasswordLoading ? "Sending..." : "Forgot your password?" }}
|
|
124
158
|
</a>
|
|
125
159
|
</p>
|
|
126
160
|
</div>
|
|
127
161
|
</slot>
|
|
128
162
|
|
|
163
|
+
<!-- Success message slot -->
|
|
164
|
+
<slot
|
|
165
|
+
name="success-message"
|
|
166
|
+
:message="forgotPasswordMessage"
|
|
167
|
+
>
|
|
168
|
+
<div
|
|
169
|
+
v-if="forgotPasswordMessage"
|
|
170
|
+
class="success-message"
|
|
171
|
+
>
|
|
172
|
+
{{ forgotPasswordMessage }}
|
|
173
|
+
</div>
|
|
174
|
+
</slot>
|
|
175
|
+
|
|
129
176
|
<!-- Error message slot -->
|
|
130
177
|
<slot
|
|
131
178
|
name="error-message"
|
|
@@ -143,5 +190,5 @@ const handleSubmit = async () => {
|
|
|
143
190
|
</template>
|
|
144
191
|
|
|
145
192
|
<style scoped>
|
|
146
|
-
section{background:var(--color-bg-primary);border:1px solid var(--color-border);border-radius:.75em;box-shadow:0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px -1px rgba(0,0,0,.06);margin:0 auto;max-width:25rem;padding:1em}form{gap:1.5rem}.form-group,form{display:flex;flex-direction:column}label{display:block;font-weight:500;margin-bottom:.5em}input[type=email],input[type=password],label{color:var(--color-gray-700);font-size:.875rem}input[type=email],input[type=password]{background-color:var(--color-bg-secondary);border:1px solid var(--color-border-light);border-radius:8px;box-sizing:border-box;padding:.75em 1em;transition:all .2s ease-in-out;width:100%}input[type=email]:focus,input[type=password]:focus{background-color:var(--color-bg-primary);border-color:var(--color-primary);box-shadow:0 0 0 3px rgba(59,130,246,.1);outline:none}.login-header{margin-bottom:1em;text-align:center}.login-title{color:var(--color-gray-800);font-size:1.875rem;font-weight:700;line-height:1.2;margin:0 0 .5em}.login-subtitle{color:var(--color-gray-500);font-size:.875rem;line-height:1.5;margin:0}.remember-me{align-items:center;display:flex;gap:.5rem}input[type=checkbox]{margin:0;width:auto}.remember-me label{color:var(--color-gray-700);font-size:.875rem;margin:0}button[type=submit]{align-items:center;background-color:var(--color-primary);border:1px solid var(--color-primary);border-radius:8px;color:var(--color-white);cursor:pointer;display:flex;font-size:.875rem;font-weight:500;gap:.5rem;justify-content:center;min-height:44px;padding:.75em 1em;transition:all .2s ease-in-out;width:100%}button[type=submit]:hover:not(:disabled){background-color:var(--color-primary-dark);border-color:var(--color-primary-dark)}button[type=submit]:disabled{cursor:not-allowed;opacity:.6}.loading-spinner{animation:spin 1s linear infinite;border:2px solid var(--color-white);border-radius:50%;border-top:2px solid transparent;height:16px;width:16px}@keyframes spin{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}.login-footer{margin-top:1em;text-align:center}.forgot-password{margin:0}.forgot-link{color:var(--color-primary);font-size:.875rem;text-decoration:none;transition:color .2s ease-in-out}.forgot-link:hover{color:var(--color-primary-dark);text-decoration:underline}.error-message{background-color:var(--color-error-light);border:1px solid var(--color-error-border);border-radius:8px;color:var(--color-error)
|
|
193
|
+
section{background:linear-gradient(135deg,var(--color-bg-primary) 0,var(--color-bg-secondary) 100%);border:1px solid var(--color-border);border-radius:.75em;box-shadow:0 4px 6px -1px rgba(0,0,0,.1),0 2px 4px -1px rgba(0,0,0,.06);margin:0 auto;max-width:25rem;padding:1em}form{gap:1.5rem}.form-group,form{display:flex;flex-direction:column}label{display:block;font-weight:500;margin-bottom:.5em}input[type=email],input[type=password],label{color:var(--color-gray-700);font-size:.875rem}input[type=email],input[type=password]{background-color:var(--color-bg-secondary);border:1px solid var(--color-border-light);border-radius:8px;box-sizing:border-box;padding:.75em 1em;transition:all .2s ease-in-out;width:100%}input[type=email]:focus,input[type=password]:focus{background-color:var(--color-bg-primary);border-color:var(--color-primary);box-shadow:0 0 0 3px rgba(59,130,246,.1);outline:none}.login-header{margin-bottom:1em;text-align:center}.login-title{color:var(--color-gray-800);font-size:1.875rem;font-weight:700;line-height:1.2;margin:0 0 .5em}.login-subtitle{color:var(--color-gray-500);font-size:.875rem;line-height:1.5;margin:0}.remember-me{align-items:center;display:flex;gap:.5rem}input[type=checkbox]{margin:0;width:auto}.remember-me label{color:var(--color-gray-700);font-size:.875rem;margin:0}button[type=submit]{align-items:center;background-color:var(--color-primary);border:1px solid var(--color-primary);border-radius:8px;color:var(--color-white);cursor:pointer;display:flex;font-size:.875rem;font-weight:500;gap:.5rem;justify-content:center;min-height:44px;padding:.75em 1em;transition:all .2s ease-in-out;width:100%}button[type=submit]:hover:not(:disabled){background-color:var(--color-primary-dark);border-color:var(--color-primary-dark)}button[type=submit]:disabled{cursor:not-allowed;opacity:.6}.loading-spinner{animation:spin 1s linear infinite;border:2px solid var(--color-white);border-radius:50%;border-top:2px solid transparent;height:16px;width:16px}@keyframes spin{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}.login-footer{margin-top:1em;text-align:center}.forgot-password{margin:0}.forgot-link{align-items:center;color:var(--color-primary);display:inline-flex;font-size:.875rem;gap:.5rem;text-decoration:none;transition:color .2s ease-in-out}.forgot-link:hover:not(.loading){color:var(--color-primary-dark);text-decoration:underline}.forgot-link.loading{cursor:not-allowed;opacity:.6;pointer-events:none}.error-message{background-color:var(--color-error-light);border:1px solid var(--color-error-border);border-radius:8px;color:var(--color-error)}.error-message,.success-message{font-size:.875rem;margin-top:1em;padding:.75em 1em;text-align:center}.success-message{background-color:var(--color-success-light);border:1px solid var(--color-success-border);border-radius:8px;color:var(--color-success)}@media (max-width:480px){.login-form-container{margin:1em;padding:1.5em}.login-title{font-size:1.5rem}}
|
|
147
194
|
</style>
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { LoginFormData, LoginFormProps, User } from '../../types.js';
|
|
2
2
|
declare var __VLS_1: {}, __VLS_3: {}, __VLS_5: {}, __VLS_7: {}, __VLS_9: {}, __VLS_11: {}, __VLS_13: {
|
|
3
|
+
message: string;
|
|
4
|
+
}, __VLS_15: {
|
|
3
5
|
error: string;
|
|
4
6
|
};
|
|
5
7
|
type __VLS_Slots = {} & {
|
|
@@ -15,19 +17,26 @@ type __VLS_Slots = {} & {
|
|
|
15
17
|
} & {
|
|
16
18
|
footer?: (props: typeof __VLS_11) => any;
|
|
17
19
|
} & {
|
|
18
|
-
'
|
|
20
|
+
'success-message'?: (props: typeof __VLS_13) => any;
|
|
21
|
+
} & {
|
|
22
|
+
'error-message'?: (props: typeof __VLS_15) => any;
|
|
19
23
|
};
|
|
20
24
|
declare const __VLS_component: import("vue").DefineComponent<LoginFormProps, void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
21
25
|
error: (error: string) => any;
|
|
22
26
|
submit: (data: LoginFormData) => any;
|
|
23
27
|
success: (user: User) => any;
|
|
28
|
+
"forgot-password-error": (error: string) => any;
|
|
29
|
+
"forgot-password-success": () => any;
|
|
24
30
|
}, string, import("vue").PublicProps, Readonly<LoginFormProps> & Readonly<{
|
|
25
31
|
onError?: ((error: string) => any) | undefined;
|
|
26
32
|
onSubmit?: ((data: LoginFormData) => any) | undefined;
|
|
27
33
|
onSuccess?: ((user: User) => any) | undefined;
|
|
34
|
+
"onForgot-password-error"?: ((error: string) => any) | undefined;
|
|
35
|
+
"onForgot-password-success"?: (() => any) | undefined;
|
|
28
36
|
}>, {
|
|
29
37
|
apiEndpoint: string;
|
|
30
38
|
redirectTo: string;
|
|
39
|
+
forgotPasswordEndpoint: string;
|
|
31
40
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
32
41
|
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
|
33
42
|
export default _default;
|
package/dist/runtime/plugin.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { defineNuxtPlugin, useRuntimeConfig } from "#app";
|
|
1
|
+
import { addRouteMiddleware, defineNuxtPlugin, useRuntimeConfig, navigateTo } from "#app";
|
|
2
2
|
import { checkTableExists } from "../utils";
|
|
3
|
+
import { useAuth } from "./composables/useAuth.js";
|
|
3
4
|
export default defineNuxtPlugin(async (_nuxtApp) => {
|
|
4
5
|
const { nuxtUsers } = useRuntimeConfig();
|
|
5
6
|
const options = nuxtUsers;
|
|
@@ -7,4 +8,20 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
|
|
|
7
8
|
if (!hasMigrationsTable) {
|
|
8
9
|
console.warn("[Nuxt Users] \u26A0\uFE0F Migrations table does not exist, you should run the migration script to create it by running: npx nuxt-users migrate");
|
|
9
10
|
}
|
|
11
|
+
addRouteMiddleware(
|
|
12
|
+
"auth.global",
|
|
13
|
+
(to, from) => {
|
|
14
|
+
if (to.path === "/login") {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const { user } = useAuth();
|
|
18
|
+
if (user.value || nuxtUsers.auth?.whitelist?.includes(to.path)) {
|
|
19
|
+
console.log("[Nuxt Users] \u{1F510} Auth middleware: Access allowed");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
console.log(`[Nuxt Users] \u{1F510} Auth middleware: Redirecting from ${from.path} to login - no user and not whitelisted`);
|
|
23
|
+
return navigateTo("/login");
|
|
24
|
+
},
|
|
25
|
+
{ global: true }
|
|
26
|
+
);
|
|
10
27
|
});
|
package/package.json
CHANGED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { defineNuxtRouteMiddleware, useRuntimeConfig, navigateTo } from "#app";
|
|
2
|
-
import { useAuth } from "../composables/useAuth.js";
|
|
3
|
-
export default defineNuxtRouteMiddleware((to, _from) => {
|
|
4
|
-
const { nuxtUsers } = useRuntimeConfig();
|
|
5
|
-
const { user } = useAuth();
|
|
6
|
-
if (to.path === "/login") {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (!user.value && !nuxtUsers.auth?.whitelist?.includes(to.path)) {
|
|
10
|
-
return navigateTo("/login");
|
|
11
|
-
}
|
|
12
|
-
});
|