nuxt-users 1.2.0 → 1.3.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 +21 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +9 -0
- package/dist/runtime/assets/colors.css +1 -1
- package/dist/runtime/components/LoginForm.vue +6 -4
- package/dist/runtime/components/LogoutLink.vue +62 -0
- package/dist/runtime/components/LogoutLink.vue.d.ts +20 -0
- package/dist/runtime/composables/useAuth.d.ts +1 -0
- package/dist/runtime/composables/useAuth.js +13 -1
- package/dist/runtime/server/api/login.post.js +1 -1
- package/dist/runtime/server/api/logout.get.d.ts +4 -0
- package/dist/runtime/server/api/logout.get.js +21 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## v1.3.0
|
|
5
|
+
|
|
6
|
+
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.2.0...v1.3.0)
|
|
7
|
+
|
|
8
|
+
### 🚀 Enhancements
|
|
9
|
+
|
|
10
|
+
- Adds theme support with light/dark mode ([005ea87](https://github.com/rrd108/nuxt-users/commit/005ea87))
|
|
11
|
+
- Adds logout functionality ([a61b4e8](https://github.com/rrd108/nuxt-users/commit/a61b4e8))
|
|
12
|
+
|
|
13
|
+
### 💅 Refactors
|
|
14
|
+
|
|
15
|
+
- Restyles login form for better UX closes #51 ([#51](https://github.com/rrd108/nuxt-users/issues/51))
|
|
16
|
+
|
|
17
|
+
### 🏡 Chore
|
|
18
|
+
|
|
19
|
+
- **release:** V1.2.0 ([54fd5c8](https://github.com/rrd108/nuxt-users/commit/54fd5c8))
|
|
20
|
+
|
|
21
|
+
### ❤️ Contributors
|
|
22
|
+
|
|
23
|
+
- Rrd108 ([@rrd108](https://github.com/rrd108))
|
|
24
|
+
|
|
4
25
|
## v1.2.0
|
|
5
26
|
|
|
6
27
|
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.1.6...v1.2.0)
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -75,6 +75,11 @@ const module = defineNuxtModule({
|
|
|
75
75
|
method: "post",
|
|
76
76
|
handler: resolver.resolve("./runtime/server/api/auth/reset-password.post")
|
|
77
77
|
});
|
|
78
|
+
addServerHandler({
|
|
79
|
+
route: "/api/logout",
|
|
80
|
+
method: "get",
|
|
81
|
+
handler: resolver.resolve("./runtime/server/api/logout.get")
|
|
82
|
+
});
|
|
78
83
|
addComponent({
|
|
79
84
|
name: "LoginForm",
|
|
80
85
|
filePath: resolver.resolve("./runtime/components/LoginForm.vue")
|
|
@@ -87,6 +92,10 @@ const module = defineNuxtModule({
|
|
|
87
92
|
name: "ResetPasswordForm",
|
|
88
93
|
filePath: resolver.resolve("./runtime/components/ResetPasswordForm.vue")
|
|
89
94
|
});
|
|
95
|
+
addComponent({
|
|
96
|
+
name: "LogoutLink",
|
|
97
|
+
filePath: resolver.resolve("./runtime/components/LogoutLink.vue")
|
|
98
|
+
});
|
|
90
99
|
nuxt.options.css = nuxt.options.css || [];
|
|
91
100
|
nuxt.options.css.push(resolver.resolve("./runtime/assets/colors.css"));
|
|
92
101
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
:root{--color-primary:#3b82f6;--color-primary-dark:#2563eb;--color-primary-light:#60a5fa;--color-secondary:#059669;--color-secondary-dark:#047857;--color-secondary-light:#10b981;--color-white:#fff;--color-black:#000;--color-gray-50:#f9fafb;--color-gray-100:#f3f4f6;--color-gray-200:#e5e7eb;--color-gray-300:#d1d5db;--color-gray-400:#9ca3af;--color-gray-500:#6b7280;--color-gray-600:#4b5563;--color-gray-700:#374151;--color-gray-800:#1f2937;--color-gray-900:#111827;--color-success:#059669;--color-success-light:#f0fdf4;--color-warning:#f59e0b;--color-warning-light:#fef3c7;--color-warning-text:#92400e;--color-error:#dc2626;--color-error-light:#fef2f2;--color-error-border:#fecaca;--color-error-alt:#db5050;--color-border:#e5e7eb;--color-border-light:#d1d5db;--color-border-dark:#ccc;--color-bg-primary:#fff;--color-bg-secondary:#f9fafb;--color-bg-tertiary:#f3f4f6}
|
|
1
|
+
:root{--color-primary:#60a5fa;--color-primary-dark:#3b82f6;--color-primary-light:#93c5fd;--color-secondary:#10b981;--color-secondary-dark:#059669;--color-secondary-light:#34d399;--color-white:#000;--color-black:#fff;--color-gray-50:#111827;--color-gray-100:#1f2937;--color-gray-200:#374151;--color-gray-300:#4b5563;--color-gray-400:#6b7280;--color-gray-500:#9ca3af;--color-gray-600:#d1d5db;--color-gray-700:#e5e7eb;--color-gray-800:#f3f4f6;--color-gray-900:#f9fafb;--color-success:#10b981;--color-success-light:#064e3b;--color-warning:#fbbf24;--color-warning-light:#451a03;--color-warning-text:#fef3c7;--color-error:#ef4444;--color-error-light:#450a0a;--color-error-border:#7f1d1d;--color-error-alt:#f87171;--color-border:#374151;--color-border-light:#4b5563;--color-border-dark:#6b7280;--color-bg-primary:#111827;--color-bg-secondary:#1f2937;--color-bg-tertiary:#374151}@media (prefers-color-scheme:light){.light,:root{--color-primary:#3b82f6;--color-primary-dark:#2563eb;--color-primary-light:#60a5fa;--color-secondary:#059669;--color-secondary-dark:#047857;--color-secondary-light:#10b981;--color-white:#fff;--color-black:#000;--color-gray-50:#f9fafb;--color-gray-100:#f3f4f6;--color-gray-200:#e5e7eb;--color-gray-300:#d1d5db;--color-gray-400:#9ca3af;--color-gray-500:#6b7280;--color-gray-600:#4b5563;--color-gray-700:#374151;--color-gray-800:#1f2937;--color-gray-900:#111827;--color-success:#059669;--color-success-light:#f0fdf4;--color-warning:#f59e0b;--color-warning-light:#fef3c7;--color-warning-text:#92400e;--color-error:#dc2626;--color-error-light:#fef2f2;--color-error-border:#fecaca;--color-error-alt:#db5050;--color-border:#e5e7eb;--color-border-light:#d1d5db;--color-border-dark:#ccc;--color-bg-primary:#fff;--color-bg-secondary:#f9fafb;--color-bg-tertiary:#f3f4f6}}
|
|
@@ -40,7 +40,7 @@ const handleSubmit = async () => {
|
|
|
40
40
|
</script>
|
|
41
41
|
|
|
42
42
|
<template>
|
|
43
|
-
<
|
|
43
|
+
<section>
|
|
44
44
|
<form @submit.prevent="handleSubmit">
|
|
45
45
|
<!-- Header slot -->
|
|
46
46
|
<slot name="header">
|
|
@@ -119,7 +119,9 @@ const handleSubmit = async () => {
|
|
|
119
119
|
<a
|
|
120
120
|
href="#"
|
|
121
121
|
class="forgot-link"
|
|
122
|
-
>
|
|
122
|
+
>
|
|
123
|
+
Forgot your password?
|
|
124
|
+
</a>
|
|
123
125
|
</p>
|
|
124
126
|
</div>
|
|
125
127
|
</slot>
|
|
@@ -137,9 +139,9 @@ const handleSubmit = async () => {
|
|
|
137
139
|
</div>
|
|
138
140
|
</slot>
|
|
139
141
|
</form>
|
|
140
|
-
</
|
|
142
|
+
</section>
|
|
141
143
|
</template>
|
|
142
144
|
|
|
143
145
|
<style scoped>
|
|
144
|
-
|
|
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);font-size:.875rem;margin-top:1em;padding:.75em 1em;text-align:center}@media (max-width:480px){.login-form-container{margin:1em;padding:1.5em}.login-title{font-size:1.5rem}}
|
|
145
147
|
</style>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { ref } from "vue";
|
|
3
|
+
import { navigateTo } from "#app";
|
|
4
|
+
import { useAuth } from "../composables/useAuth";
|
|
5
|
+
const props = defineProps({
|
|
6
|
+
redirectTo: { type: String, required: false, default: "/login" },
|
|
7
|
+
linkText: { type: String, required: false, default: "Logout" },
|
|
8
|
+
confirmMessage: { type: String, required: false, default: "Are you sure you want to logout?" },
|
|
9
|
+
class: { type: String, required: false }
|
|
10
|
+
});
|
|
11
|
+
const emit = defineEmits(["success", "click", "error"]);
|
|
12
|
+
const { logout } = useAuth();
|
|
13
|
+
const isLoading = ref(false);
|
|
14
|
+
const error = ref("");
|
|
15
|
+
const handleLogout = async (event) => {
|
|
16
|
+
event.preventDefault();
|
|
17
|
+
if (!confirm(props.confirmMessage)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
isLoading.value = true;
|
|
21
|
+
error.value = "";
|
|
22
|
+
try {
|
|
23
|
+
emit("click");
|
|
24
|
+
await logout();
|
|
25
|
+
emit("success");
|
|
26
|
+
if (props.redirectTo) {
|
|
27
|
+
await navigateTo(props.redirectTo);
|
|
28
|
+
}
|
|
29
|
+
} catch (err) {
|
|
30
|
+
const errorMessage = err instanceof Error ? err.message : "Logout failed";
|
|
31
|
+
error.value = errorMessage;
|
|
32
|
+
emit("error", errorMessage);
|
|
33
|
+
} finally {
|
|
34
|
+
isLoading.value = false;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<template>
|
|
40
|
+
<div>
|
|
41
|
+
<div
|
|
42
|
+
v-if="error"
|
|
43
|
+
class="error-message"
|
|
44
|
+
>
|
|
45
|
+
{{ error }}
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
<a
|
|
49
|
+
href="#"
|
|
50
|
+
:class="['logout-link', { loading: isLoading }, props.class]"
|
|
51
|
+
:disabled="isLoading"
|
|
52
|
+
@click="handleLogout"
|
|
53
|
+
>
|
|
54
|
+
<span v-if="isLoading">Logging out...</span>
|
|
55
|
+
<span v-else>{{ linkText }}</span>
|
|
56
|
+
</a>
|
|
57
|
+
</div>
|
|
58
|
+
</template>
|
|
59
|
+
|
|
60
|
+
<style scoped>
|
|
61
|
+
.logout-link{color:#dc3545;cursor:pointer;font-size:.875rem;font-weight:500;text-decoration:none;transition:color .2s}.logout-link:hover:not(.loading){color:#c82333;text-decoration:underline}.logout-link.loading{cursor:not-allowed;opacity:.6;pointer-events:none}.error-message{color:#dc3545;font-size:.875rem;margin-bottom:.5rem}
|
|
62
|
+
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface LogoutLinkProps {
|
|
2
|
+
redirectTo?: string;
|
|
3
|
+
linkText?: string;
|
|
4
|
+
confirmMessage?: string;
|
|
5
|
+
class?: string;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: import("vue").DefineComponent<LogoutLinkProps, void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
8
|
+
click: () => any;
|
|
9
|
+
error: (error: string) => any;
|
|
10
|
+
success: () => any;
|
|
11
|
+
}, string, import("vue").PublicProps, Readonly<LogoutLinkProps> & Readonly<{
|
|
12
|
+
onClick?: (() => any) | undefined;
|
|
13
|
+
onError?: ((error: string) => any) | undefined;
|
|
14
|
+
onSuccess?: (() => any) | undefined;
|
|
15
|
+
}>, {
|
|
16
|
+
redirectTo: string;
|
|
17
|
+
linkText: string;
|
|
18
|
+
confirmMessage: string;
|
|
19
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
20
|
+
export default _default;
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { useState } from "#app";
|
|
2
2
|
export const useAuth = () => {
|
|
3
3
|
const user = useState("user", () => null);
|
|
4
|
+
const logout = async () => {
|
|
5
|
+
try {
|
|
6
|
+
await $fetch("/api/logout", {
|
|
7
|
+
method: "GET"
|
|
8
|
+
});
|
|
9
|
+
user.value = null;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error("Logout failed:", error);
|
|
12
|
+
user.value = null;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
4
15
|
return {
|
|
5
|
-
user
|
|
16
|
+
user,
|
|
17
|
+
logout
|
|
6
18
|
};
|
|
7
19
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineEventHandler, getCookie, setCookie } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
import { useDb } from "../../../utils";
|
|
4
|
+
export default defineEventHandler(async (event) => {
|
|
5
|
+
const { nuxtUsers } = useRuntimeConfig();
|
|
6
|
+
const options = nuxtUsers;
|
|
7
|
+
const db = await useDb(options);
|
|
8
|
+
const personalAccessTokensTable = options.tables.personalAccessTokens;
|
|
9
|
+
const token = getCookie(event, "auth_token");
|
|
10
|
+
if (token) {
|
|
11
|
+
await db.sql`DELETE FROM {${personalAccessTokensTable}} WHERE token = ${token}`;
|
|
12
|
+
}
|
|
13
|
+
setCookie(event, "auth_token", "", {
|
|
14
|
+
httpOnly: true,
|
|
15
|
+
secure: process.env.NODE_ENV === "production",
|
|
16
|
+
sameSite: "lax",
|
|
17
|
+
maxAge: 0,
|
|
18
|
+
path: "/"
|
|
19
|
+
});
|
|
20
|
+
return { message: "Logged out successfully" };
|
|
21
|
+
});
|