@webx-ui/module-auth 0.0.1
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/LICENSE +21 -0
- package/README.md +84 -0
- package/dist/LoginCard.d.ts +40 -0
- package/dist/UserMenu.d.ts +10 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +309 -0
- package/dist/index.js.map +1 -0
- package/dist/session.d.ts +24 -0
- package/dist/style.css +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 webx-ui
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# @webx-ui/module-auth
|
|
2
|
+
|
|
3
|
+
Signing in to a WebX UI admin panel: the screen, the session and the router guard.
|
|
4
|
+
|
|
5
|
+
The front-end half of the Composer package
|
|
6
|
+
[`webx-ui/module-auth`](https://packagist.org/packages/webx-ui/module-auth), which is what
|
|
7
|
+
closes the panel on the server. This is what lets somebody back in.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @webx-ui/module-auth @webx-ui/admin @webx-ui/core vue vue-router
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createAdmin } from '@webx-ui/admin'
|
|
17
|
+
import { auth, WxUserMenu } from '@webx-ui/module-auth'
|
|
18
|
+
|
|
19
|
+
createAdmin({
|
|
20
|
+
plugins: [auth()],
|
|
21
|
+
userMenu: WxUserMenu,
|
|
22
|
+
}).mount()
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
That is the whole integration. Installing it also tells the panel how to find out who is signed
|
|
26
|
+
in, which is why `@webx-ui/admin` knows nothing about authentication — it holds the answer, not
|
|
27
|
+
the question.
|
|
28
|
+
|
|
29
|
+
## A plugin, not a section
|
|
30
|
+
|
|
31
|
+
It owns a route and a guard and has no place in the menu:
|
|
32
|
+
|
|
33
|
+
- `/login` renders the card
|
|
34
|
+
- a guard sends anybody without a session there, remembering where they were going
|
|
35
|
+
- a watcher brings them back when the session arrives, and out again when it ends — a sign-out
|
|
36
|
+
in another tab, an account switched off
|
|
37
|
+
|
|
38
|
+
Redirects are driven by the panel's state rather than by an event from the card. Signing in
|
|
39
|
+
flips the panel to `ready`, the shell swaps the branch it renders, and the card is unmounted
|
|
40
|
+
before the line after `await` runs.
|
|
41
|
+
|
|
42
|
+
## The card
|
|
43
|
+
|
|
44
|
+
No logo, no product name, no welcome. An admin panel's front door should say as little as
|
|
45
|
+
possible to somebody who has no business behind it, and the people who do already know where
|
|
46
|
+
they are.
|
|
47
|
+
|
|
48
|
+
What it does carry: a password reveal, a Caps Lock warning, `autocomplete="username"` and
|
|
49
|
+
`current-password` so password managers work, validation errors landing on the right field, and
|
|
50
|
+
a countdown when the server throttles.
|
|
51
|
+
|
|
52
|
+
Every string is a prop. The library speaks English; the panels built with it do not have to.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
auth({
|
|
56
|
+
card: {
|
|
57
|
+
emailLabel: 'Електронна пошта',
|
|
58
|
+
passwordLabel: 'Пароль',
|
|
59
|
+
submitLabel: 'Увійти',
|
|
60
|
+
rememberLabel: 'Запам’ятати мене',
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`WxLoginCard` is exported for a panel that wants to place it itself.
|
|
66
|
+
|
|
67
|
+
## The session
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
import { useAuth } from '@webx-ui/module-auth'
|
|
71
|
+
|
|
72
|
+
const auth = useAuth()
|
|
73
|
+
|
|
74
|
+
await auth.login({ email, password, remember: true })
|
|
75
|
+
await auth.logout()
|
|
76
|
+
const user = await auth.me() // null when nobody is
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
There is nothing kept here: the session lives in a cookie, the server is the source of truth,
|
|
80
|
+
and the panel asks rather than remembers.
|
|
81
|
+
|
|
82
|
+
## Licence
|
|
83
|
+
|
|
84
|
+
MIT.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The card a panel opens on.
|
|
3
|
+
*
|
|
4
|
+
* No logo, no product name, no "welcome back" — an admin panel's front door should say as
|
|
5
|
+
* little as possible to somebody who has no business behind it, and the people who do have
|
|
6
|
+
* business behind it already know where they are.
|
|
7
|
+
*
|
|
8
|
+
* Every string is a prop. The library speaks English; the panels built with it do not have to.
|
|
9
|
+
*/
|
|
10
|
+
type __VLS_Props = {
|
|
11
|
+
emailLabel?: string;
|
|
12
|
+
passwordLabel?: string;
|
|
13
|
+
rememberLabel?: string;
|
|
14
|
+
submitLabel?: string;
|
|
15
|
+
capsLockWarning?: string;
|
|
16
|
+
throttleMessage?: string;
|
|
17
|
+
/** Offer to stay signed in. The server honours it with a long-lived cookie. */
|
|
18
|
+
remember?: boolean;
|
|
19
|
+
/** Put the cursor in the email field. Off for a card that is not the only thing on screen. */
|
|
20
|
+
autofocus?: boolean;
|
|
21
|
+
};
|
|
22
|
+
declare const _default: import('vue').DefineComponent<__VLS_Props, {
|
|
23
|
+
focus: () => void | undefined;
|
|
24
|
+
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
25
|
+
success: () => any;
|
|
26
|
+
}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
27
|
+
onSuccess?: (() => any) | undefined;
|
|
28
|
+
}>, {
|
|
29
|
+
emailLabel: string;
|
|
30
|
+
passwordLabel: string;
|
|
31
|
+
rememberLabel: string;
|
|
32
|
+
submitLabel: string;
|
|
33
|
+
capsLockWarning: string;
|
|
34
|
+
throttleMessage: string;
|
|
35
|
+
remember: boolean;
|
|
36
|
+
autofocus: boolean;
|
|
37
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {
|
|
38
|
+
emailField: unknown;
|
|
39
|
+
}, any>;
|
|
40
|
+
export default _default;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The corner of the header: who this is, and the way out.
|
|
3
|
+
*/
|
|
4
|
+
type __VLS_Props = {
|
|
5
|
+
signOutLabel?: string;
|
|
6
|
+
};
|
|
7
|
+
declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
8
|
+
signOutLabel: string;
|
|
9
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
10
|
+
export default _default;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AdminPlugin } from '@webx-ui/admin';
|
|
2
|
+
export interface AuthOptions {
|
|
3
|
+
/** Where the sign-in screen lives, inside the panel. */
|
|
4
|
+
path?: string;
|
|
5
|
+
/** Props handed to the card — the labels, mostly. */
|
|
6
|
+
card?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Signing in, as a plugin rather than a section: it owns a route and a guard, and it has no
|
|
10
|
+
* place in the menu.
|
|
11
|
+
*
|
|
12
|
+
* Installing it also tells the panel how to find out who is signed in, which is why the panel
|
|
13
|
+
* itself knows nothing about authentication — it holds the answer, not the question.
|
|
14
|
+
*/
|
|
15
|
+
export declare function auth(options?: AuthOptions): AdminPlugin;
|
|
16
|
+
export { createAuthSession, provideAuth, useAuth, authKey } from './session';
|
|
17
|
+
export type { AuthSession, Credentials } from './session';
|
|
18
|
+
export { default as WxLoginCard } from './LoginCard';
|
|
19
|
+
export { default as WxUserMenu } from './UserMenu';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { inject as J, defineComponent as N, ref as c, useTemplateRef as Q, onBeforeUnmount as X, computed as k, resolveComponent as l, openBlock as g, createBlock as h, withCtx as u, createVNode as s, withModifiers as Y, createCommentVNode as U, createTextVNode as M, toDisplayString as $, unref as Z, h as ee, watch as te } from "vue";
|
|
2
|
+
import { HttpError as ae, useAdmin as oe } from "@webx-ui/admin";
|
|
3
|
+
const W = /* @__PURE__ */ Symbol("webx-auth");
|
|
4
|
+
function j() {
|
|
5
|
+
const e = J(W, null);
|
|
6
|
+
if (e === null)
|
|
7
|
+
throw new Error("useAuth() was called outside a panel that installed the auth plugin.");
|
|
8
|
+
return e;
|
|
9
|
+
}
|
|
10
|
+
function ne(e) {
|
|
11
|
+
const a = `${e.apiPath}/auth`;
|
|
12
|
+
return {
|
|
13
|
+
async me() {
|
|
14
|
+
try {
|
|
15
|
+
return (await e.http.get(`${a}/me`)).data;
|
|
16
|
+
} catch (t) {
|
|
17
|
+
if (se(t))
|
|
18
|
+
return null;
|
|
19
|
+
throw t;
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
async login(t) {
|
|
23
|
+
const n = await e.http.post(`${a}/login`, {
|
|
24
|
+
email: t.email,
|
|
25
|
+
password: t.password,
|
|
26
|
+
remember: t.remember ?? !1
|
|
27
|
+
});
|
|
28
|
+
return e.setUser(n.data), await e.reload(), n.data;
|
|
29
|
+
},
|
|
30
|
+
async logout() {
|
|
31
|
+
try {
|
|
32
|
+
await e.http.post(`${a}/logout`);
|
|
33
|
+
} finally {
|
|
34
|
+
e.setUser(null), e.state.status = "unauthenticated", e.state.manifest = null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function le(e, a) {
|
|
40
|
+
e.provide(W, a);
|
|
41
|
+
}
|
|
42
|
+
function se(e) {
|
|
43
|
+
return typeof e == "object" && e !== null && "status" in e && e.status === 401;
|
|
44
|
+
}
|
|
45
|
+
const ue = /* @__PURE__ */ N({
|
|
46
|
+
__name: "LoginCard",
|
|
47
|
+
props: {
|
|
48
|
+
emailLabel: { default: "Email" },
|
|
49
|
+
passwordLabel: { default: "Password" },
|
|
50
|
+
rememberLabel: { default: "Stay signed in" },
|
|
51
|
+
submitLabel: { default: "Sign in" },
|
|
52
|
+
capsLockWarning: { default: "Caps Lock is on." },
|
|
53
|
+
throttleMessage: { default: "Too many attempts. Try again in {seconds} s." },
|
|
54
|
+
remember: { type: Boolean, default: !0 },
|
|
55
|
+
autofocus: { type: Boolean, default: !0 }
|
|
56
|
+
},
|
|
57
|
+
emits: ["success"],
|
|
58
|
+
setup(e, { expose: a, emit: t }) {
|
|
59
|
+
const n = e, i = t, d = j(), r = c(""), v = c(""), _ = c(!1), f = c(!1), m = c(!1), y = c(!1), w = c(""), C = c({}), x = c(0), A = Q("emailField");
|
|
60
|
+
let L = null;
|
|
61
|
+
X(S);
|
|
62
|
+
const V = k(() => x.value > 0), q = k(
|
|
63
|
+
() => n.throttleMessage.replace("{seconds}", String(x.value))
|
|
64
|
+
);
|
|
65
|
+
async function F() {
|
|
66
|
+
if (!(f.value || V.value)) {
|
|
67
|
+
f.value = !0, w.value = "", C.value = {};
|
|
68
|
+
try {
|
|
69
|
+
await d.login({
|
|
70
|
+
email: r.value,
|
|
71
|
+
password: v.value,
|
|
72
|
+
remember: _.value
|
|
73
|
+
}), v.value = "", i("success");
|
|
74
|
+
} catch (o) {
|
|
75
|
+
I(o);
|
|
76
|
+
} finally {
|
|
77
|
+
f.value = !1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function I(o) {
|
|
82
|
+
if (!(o instanceof ae)) {
|
|
83
|
+
w.value = o instanceof Error ? o.message : String(o);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (o.isValidation) {
|
|
87
|
+
C.value = o.errors;
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (o.isThrottled) {
|
|
91
|
+
K(o.retryAfter ?? 60);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
w.value = o.message;
|
|
95
|
+
}
|
|
96
|
+
function K(o) {
|
|
97
|
+
S(), x.value = o, L = setInterval(() => {
|
|
98
|
+
x.value -= 1, x.value <= 0 && S();
|
|
99
|
+
}, 1e3);
|
|
100
|
+
}
|
|
101
|
+
function S() {
|
|
102
|
+
L !== null && (clearInterval(L), L = null), x.value = 0;
|
|
103
|
+
}
|
|
104
|
+
function z(o) {
|
|
105
|
+
y.value = o.getModifierState("CapsLock");
|
|
106
|
+
}
|
|
107
|
+
return a({ focus: () => A.value?.focus() }), (o, p) => {
|
|
108
|
+
const B = l("wx-alert"), E = l("wx-icon"), P = l("wx-input"), T = l("wx-form-item"), O = l("wx-action"), R = l("wx-checkbox"), H = l("wx-button"), D = l("wx-form"), G = l("wx-card");
|
|
109
|
+
return g(), h(G, {
|
|
110
|
+
class: "wx-login",
|
|
111
|
+
padding: 24
|
|
112
|
+
}, {
|
|
113
|
+
default: u(() => [
|
|
114
|
+
s(D, {
|
|
115
|
+
errors: C.value,
|
|
116
|
+
disabled: f.value,
|
|
117
|
+
gap: "md",
|
|
118
|
+
onSubmit: Y(F, ["prevent"])
|
|
119
|
+
}, {
|
|
120
|
+
default: u(() => [
|
|
121
|
+
w.value !== "" ? (g(), h(B, {
|
|
122
|
+
key: 0,
|
|
123
|
+
type: "danger",
|
|
124
|
+
variant: "soft",
|
|
125
|
+
live: "",
|
|
126
|
+
description: w.value,
|
|
127
|
+
class: "wx-login__message"
|
|
128
|
+
}, null, 8, ["description"])) : V.value ? (g(), h(B, {
|
|
129
|
+
key: 1,
|
|
130
|
+
type: "warning",
|
|
131
|
+
variant: "soft",
|
|
132
|
+
live: "",
|
|
133
|
+
description: q.value,
|
|
134
|
+
class: "wx-login__message"
|
|
135
|
+
}, null, 8, ["description"])) : U("", !0),
|
|
136
|
+
s(T, { name: "email" }, {
|
|
137
|
+
default: u(() => [
|
|
138
|
+
s(P, {
|
|
139
|
+
ref_key: "emailField",
|
|
140
|
+
ref: A,
|
|
141
|
+
modelValue: r.value,
|
|
142
|
+
"onUpdate:modelValue": p[0] || (p[0] = (b) => r.value = b),
|
|
143
|
+
type: "email",
|
|
144
|
+
placeholder: e.emailLabel,
|
|
145
|
+
"aria-label": e.emailLabel,
|
|
146
|
+
autocomplete: "username",
|
|
147
|
+
autofocus: e.autofocus,
|
|
148
|
+
inputmode: "email",
|
|
149
|
+
size: "lg"
|
|
150
|
+
}, {
|
|
151
|
+
prefix: u(() => [
|
|
152
|
+
s(E, { name: "mail" })
|
|
153
|
+
]),
|
|
154
|
+
_: 1
|
|
155
|
+
}, 8, ["modelValue", "placeholder", "aria-label", "autofocus"])
|
|
156
|
+
]),
|
|
157
|
+
_: 1
|
|
158
|
+
}),
|
|
159
|
+
s(T, {
|
|
160
|
+
name: "password",
|
|
161
|
+
help: y.value ? e.capsLockWarning : void 0
|
|
162
|
+
}, {
|
|
163
|
+
default: u(() => [
|
|
164
|
+
s(P, {
|
|
165
|
+
modelValue: v.value,
|
|
166
|
+
"onUpdate:modelValue": p[2] || (p[2] = (b) => v.value = b),
|
|
167
|
+
type: m.value ? "text" : "password",
|
|
168
|
+
placeholder: e.passwordLabel,
|
|
169
|
+
"aria-label": e.passwordLabel,
|
|
170
|
+
autocomplete: "current-password",
|
|
171
|
+
size: "lg",
|
|
172
|
+
onKeydown: z,
|
|
173
|
+
onKeyup: z
|
|
174
|
+
}, {
|
|
175
|
+
prefix: u(() => [
|
|
176
|
+
s(E, { name: "lock" })
|
|
177
|
+
]),
|
|
178
|
+
suffix: u(() => [
|
|
179
|
+
s(O, {
|
|
180
|
+
icon: m.value ? "eye-off" : "eye",
|
|
181
|
+
title: m.value ? "Hide the password" : "Show the password",
|
|
182
|
+
tabindex: "-1",
|
|
183
|
+
onClick: p[1] || (p[1] = (b) => m.value = !m.value)
|
|
184
|
+
}, null, 8, ["icon", "title"])
|
|
185
|
+
]),
|
|
186
|
+
_: 1
|
|
187
|
+
}, 8, ["modelValue", "type", "placeholder", "aria-label"])
|
|
188
|
+
]),
|
|
189
|
+
_: 1
|
|
190
|
+
}, 8, ["help"]),
|
|
191
|
+
e.remember ? (g(), h(R, {
|
|
192
|
+
key: 2,
|
|
193
|
+
modelValue: _.value,
|
|
194
|
+
"onUpdate:modelValue": p[3] || (p[3] = (b) => _.value = b),
|
|
195
|
+
label: e.rememberLabel
|
|
196
|
+
}, null, 8, ["modelValue", "label"])) : U("", !0),
|
|
197
|
+
s(H, {
|
|
198
|
+
type: "primary",
|
|
199
|
+
"native-type": "submit",
|
|
200
|
+
size: "lg",
|
|
201
|
+
block: "",
|
|
202
|
+
loading: f.value,
|
|
203
|
+
disabled: V.value
|
|
204
|
+
}, {
|
|
205
|
+
default: u(() => [
|
|
206
|
+
M($(e.submitLabel), 1)
|
|
207
|
+
]),
|
|
208
|
+
_: 1
|
|
209
|
+
}, 8, ["loading", "disabled"])
|
|
210
|
+
]),
|
|
211
|
+
_: 1
|
|
212
|
+
}, 8, ["errors", "disabled"])
|
|
213
|
+
]),
|
|
214
|
+
_: 1
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}), re = (e, a) => {
|
|
219
|
+
const t = e.__vccOpts || e;
|
|
220
|
+
for (const [n, i] of a)
|
|
221
|
+
t[n] = i;
|
|
222
|
+
return t;
|
|
223
|
+
}, ie = /* @__PURE__ */ re(ue, [["__scopeId", "data-v-b1f8e87b"]]), me = /* @__PURE__ */ N({
|
|
224
|
+
__name: "UserMenu",
|
|
225
|
+
props: {
|
|
226
|
+
signOutLabel: { default: "Sign out" }
|
|
227
|
+
},
|
|
228
|
+
setup(e) {
|
|
229
|
+
const a = oe(), t = j(), n = k(() => a.state.user), i = k(() => (n.value?.name ?? "").split(/\s+/).filter((r) => r !== "").slice(0, 2).map((r) => r[0]?.toUpperCase() ?? "").join(""));
|
|
230
|
+
return (d, r) => {
|
|
231
|
+
const v = l("wx-avatar"), _ = l("wx-action"), f = l("wx-text"), m = l("wx-dropdown-item"), y = l("wx-dropdown");
|
|
232
|
+
return n.value !== null ? (g(), h(y, { key: 0 }, {
|
|
233
|
+
trigger: u(() => [
|
|
234
|
+
s(_, {
|
|
235
|
+
title: n.value.name
|
|
236
|
+
}, {
|
|
237
|
+
default: u(() => [
|
|
238
|
+
s(v, {
|
|
239
|
+
label: i.value,
|
|
240
|
+
size: "sm"
|
|
241
|
+
}, null, 8, ["label"])
|
|
242
|
+
]),
|
|
243
|
+
_: 1
|
|
244
|
+
}, 8, ["title"])
|
|
245
|
+
]),
|
|
246
|
+
default: u(() => [
|
|
247
|
+
s(m, { disabled: "" }, {
|
|
248
|
+
default: u(() => [
|
|
249
|
+
s(f, { size: "sm" }, {
|
|
250
|
+
default: u(() => [
|
|
251
|
+
M($(n.value.email), 1)
|
|
252
|
+
]),
|
|
253
|
+
_: 1
|
|
254
|
+
})
|
|
255
|
+
]),
|
|
256
|
+
_: 1
|
|
257
|
+
}),
|
|
258
|
+
s(m, {
|
|
259
|
+
icon: "logout",
|
|
260
|
+
onClick: r[0] || (r[0] = (w) => Z(t).logout())
|
|
261
|
+
}, {
|
|
262
|
+
default: u(() => [
|
|
263
|
+
M($(e.signOutLabel), 1)
|
|
264
|
+
]),
|
|
265
|
+
_: 1
|
|
266
|
+
})
|
|
267
|
+
]),
|
|
268
|
+
_: 1
|
|
269
|
+
})) : U("", !0);
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
function pe(e = {}) {
|
|
274
|
+
const a = e.path ?? "/login";
|
|
275
|
+
return {
|
|
276
|
+
install(t) {
|
|
277
|
+
const n = ne(t.context);
|
|
278
|
+
le(t.app, n), t.context.useSessionLoader(() => n.me()), t.router.addRoute({
|
|
279
|
+
path: a,
|
|
280
|
+
name: "webx.login",
|
|
281
|
+
meta: { public: !0 },
|
|
282
|
+
component: { render: () => ee(ie, { ...e.card }) }
|
|
283
|
+
}), t.router.beforeEach((i) => i.meta.public === !0 || t.context.state.status !== "unauthenticated" ? !0 : { path: a, query: i.fullPath === "/" ? {} : { next: i.fullPath } }), te(
|
|
284
|
+
() => t.context.state.status,
|
|
285
|
+
(i) => {
|
|
286
|
+
const d = t.router.currentRoute.value;
|
|
287
|
+
if (i === "unauthenticated" && d.path !== a) {
|
|
288
|
+
t.router.replace({ path: a, query: { next: d.fullPath } });
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (i === "ready" && d.path === a) {
|
|
292
|
+
const r = d.query.next;
|
|
293
|
+
t.router.replace(typeof r == "string" ? r : "/");
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
export {
|
|
301
|
+
ie as WxLoginCard,
|
|
302
|
+
me as WxUserMenu,
|
|
303
|
+
pe as auth,
|
|
304
|
+
W as authKey,
|
|
305
|
+
ne as createAuthSession,
|
|
306
|
+
le as provideAuth,
|
|
307
|
+
j as useAuth
|
|
308
|
+
};
|
|
309
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/session.ts","../src/LoginCard.vue","../src/UserMenu.vue","../src/index.ts"],"sourcesContent":["import { inject, type App, type InjectionKey } from 'vue'\nimport type { AdminContext, AdminUser } from '@webx-ui/admin'\n\nexport interface Credentials {\n email: string\n password: string\n remember?: boolean\n}\n\nexport interface AuthSession {\n /** Who is signed in, or null. A 401 is an answer, not a failure. */\n me(): Promise<AdminUser | null>\n /** Signs in and tells the panel to load itself. Throws `HttpError` on a refusal. */\n login(credentials: Credentials): Promise<AdminUser>\n logout(): Promise<void>\n}\n\nexport const authKey: InjectionKey<AuthSession> = Symbol('webx-auth')\n\nexport function useAuth(): AuthSession {\n const session = inject(authKey, null)\n\n if (session === null) {\n throw new Error('useAuth() was called outside a panel that installed the auth plugin.')\n }\n\n return session\n}\n\n/**\n * The three calls `webx-ui/module-auth` answers, and nothing else.\n *\n * The session lives in a cookie, so there is nothing to keep here: the source of truth is the\n * server, and the panel asks it rather than remembering.\n */\nexport function createAuthSession(admin: AdminContext): AuthSession {\n const base = `${admin.apiPath}/auth`\n\n return {\n async me() {\n try {\n const body = await admin.http.get<{ data: AdminUser | null }>(`${base}/me`)\n\n return body.data\n } catch (error) {\n if (isUnauthenticated(error)) {\n return null\n }\n\n throw error\n }\n },\n\n async login(credentials) {\n const body = await admin.http.post<{ data: AdminUser }>(`${base}/login`, {\n email: credentials.email,\n password: credentials.password,\n remember: credentials.remember ?? false,\n })\n\n admin.setUser(body.data)\n\n // Signing in is the moment the panel becomes knowable: the manifest needs a session,\n // so it could not have been loaded before now.\n await admin.reload()\n\n return body.data\n },\n\n async logout() {\n try {\n await admin.http.post(`${base}/logout`)\n } finally {\n // Whatever the server said, this browser is done: leaving the panel drawn behind a\n // failed sign-out would be worse than signing out optimistically.\n admin.setUser(null)\n admin.state.status = 'unauthenticated'\n admin.state.manifest = null\n }\n },\n }\n}\n\nexport function provideAuth(app: App, session: AuthSession): void {\n app.provide(authKey, session)\n}\n\nfunction isUnauthenticated(error: unknown): boolean {\n return (\n typeof error === 'object' &&\n error !== null &&\n 'status' in error &&\n (error as { status: unknown }).status === 401\n )\n}\n","<script setup lang=\"ts\">\nimport { computed, onBeforeUnmount, ref, useTemplateRef } from 'vue'\nimport { HttpError } from '@webx-ui/admin'\nimport { useAuth } from './session'\n\n/**\n * The card a panel opens on.\n *\n * No logo, no product name, no \"welcome back\" — an admin panel's front door should say as\n * little as possible to somebody who has no business behind it, and the people who do have\n * business behind it already know where they are.\n *\n * Every string is a prop. The library speaks English; the panels built with it do not have to.\n */\nconst props = withDefaults(\n defineProps<{\n emailLabel?: string\n passwordLabel?: string\n rememberLabel?: string\n submitLabel?: string\n capsLockWarning?: string\n throttleMessage?: string\n /** Offer to stay signed in. The server honours it with a long-lived cookie. */\n remember?: boolean\n /** Put the cursor in the email field. Off for a card that is not the only thing on screen. */\n autofocus?: boolean\n }>(),\n {\n emailLabel: 'Email',\n passwordLabel: 'Password',\n rememberLabel: 'Stay signed in',\n submitLabel: 'Sign in',\n capsLockWarning: 'Caps Lock is on.',\n // `{seconds}` is replaced with however long the server said to wait.\n throttleMessage: 'Too many attempts. Try again in {seconds} s.',\n remember: true,\n autofocus: true,\n },\n)\n\nconst emit = defineEmits<{ success: [] }>()\n\nconst auth = useAuth()\n\nconst email = ref('')\nconst password = ref('')\nconst rememberMe = ref(false)\n\nconst busy = ref(false)\nconst revealed = ref(false)\nconst capsLock = ref(false)\nconst message = ref('')\nconst errors = ref<Record<string, string[]>>({})\nconst secondsLeft = ref(0)\n\nconst emailField = useTemplateRef<HTMLInputElement>('emailField')\n\nlet countdown: ReturnType<typeof setInterval> | null = null\n\nonBeforeUnmount(stopCountdown)\n\nconst throttled = computed(() => secondsLeft.value > 0)\n\nconst throttleNotice = computed(() =>\n props.throttleMessage.replace('{seconds}', String(secondsLeft.value)),\n)\n\nasync function submit(): Promise<void> {\n if (busy.value || throttled.value) {\n return\n }\n\n busy.value = true\n message.value = ''\n errors.value = {}\n\n try {\n await auth.login({\n email: email.value,\n password: password.value,\n remember: rememberMe.value,\n })\n\n password.value = ''\n emit('success')\n } catch (error) {\n handle(error)\n } finally {\n busy.value = false\n }\n}\n\nfunction handle(error: unknown): void {\n if (!(error instanceof HttpError)) {\n message.value = error instanceof Error ? error.message : String(error)\n\n return\n }\n\n // A bad password comes back as a 422 against the email field, the same as an address\n // nobody owns — the server refuses to say which, and so does this.\n if (error.isValidation) {\n errors.value = error.errors\n\n return\n }\n\n if (error.isThrottled) {\n startCountdown(error.retryAfter ?? 60)\n\n return\n }\n\n message.value = error.message\n}\n\nfunction startCountdown(seconds: number): void {\n stopCountdown()\n secondsLeft.value = seconds\n\n countdown = setInterval(() => {\n secondsLeft.value -= 1\n\n if (secondsLeft.value <= 0) {\n stopCountdown()\n }\n }, 1000)\n}\n\nfunction stopCountdown(): void {\n if (countdown !== null) {\n clearInterval(countdown)\n countdown = null\n }\n\n secondsLeft.value = 0\n}\n\n/**\n * Worth saying out loud: a password typed in capitals fails with the same unhelpful message\n * as a wrong one, and people retype it three times before noticing.\n */\nfunction trackCapsLock(event: KeyboardEvent): void {\n capsLock.value = event.getModifierState('CapsLock')\n}\n\ndefineExpose({ focus: () => emailField.value?.focus() })\n</script>\n\n<template>\n <wx-card class=\"wx-login\" :padding=\"24\">\n <wx-form :errors=\"errors\" :disabled=\"busy\" gap=\"md\" @submit.prevent=\"submit\">\n <wx-alert\n v-if=\"message !== ''\"\n type=\"danger\"\n variant=\"soft\"\n live\n :description=\"message\"\n class=\"wx-login__message\"\n />\n\n <wx-alert\n v-else-if=\"throttled\"\n type=\"warning\"\n variant=\"soft\"\n live\n :description=\"throttleNotice\"\n class=\"wx-login__message\"\n />\n\n <wx-form-item name=\"email\">\n <wx-input\n ref=\"emailField\"\n v-model=\"email\"\n type=\"email\"\n :placeholder=\"emailLabel\"\n :aria-label=\"emailLabel\"\n autocomplete=\"username\"\n :autofocus=\"autofocus\"\n inputmode=\"email\"\n size=\"lg\"\n >\n <template #prefix><wx-icon name=\"mail\" /></template>\n </wx-input>\n </wx-form-item>\n\n <wx-form-item name=\"password\" :help=\"capsLock ? capsLockWarning : undefined\">\n <wx-input\n v-model=\"password\"\n :type=\"revealed ? 'text' : 'password'\"\n :placeholder=\"passwordLabel\"\n :aria-label=\"passwordLabel\"\n autocomplete=\"current-password\"\n size=\"lg\"\n @keydown=\"trackCapsLock\"\n @keyup=\"trackCapsLock\"\n >\n <template #prefix><wx-icon name=\"lock\" /></template>\n <template #suffix>\n <wx-action\n :icon=\"revealed ? 'eye-off' : 'eye'\"\n :title=\"revealed ? 'Hide the password' : 'Show the password'\"\n tabindex=\"-1\"\n @click=\"revealed = !revealed\"\n />\n </template>\n </wx-input>\n </wx-form-item>\n\n <wx-checkbox v-if=\"remember\" v-model=\"rememberMe\" :label=\"rememberLabel\" />\n\n <wx-button\n type=\"primary\"\n native-type=\"submit\"\n size=\"lg\"\n block\n :loading=\"busy\"\n :disabled=\"throttled\"\n >\n {{ submitLabel }}\n </wx-button>\n </wx-form>\n </wx-card>\n</template>\n\n<style scoped>\n.wx-login {\n width: 100%;\n /* Wide enough for an email address, narrow enough to stay a card rather than a page. */\n max-width: 26rem;\n}\n\n.wx-login__message {\n margin-block-end: var(--wx-space-4);\n}\n</style>\n","<script setup lang=\"ts\">\nimport { computed } from 'vue'\nimport { useAdmin } from '@webx-ui/admin'\nimport { useAuth } from './session'\n\n/**\n * The corner of the header: who this is, and the way out.\n */\nwithDefaults(defineProps<{ signOutLabel?: string }>(), { signOutLabel: 'Sign out' })\n\nconst admin = useAdmin()\nconst auth = useAuth()\n\nconst user = computed(() => admin.state.user)\n\nconst initials = computed(() => {\n const name = user.value?.name ?? ''\n\n return name\n .split(/\\s+/)\n .filter((part) => part !== '')\n .slice(0, 2)\n .map((part) => part[0]?.toUpperCase() ?? '')\n .join('')\n})\n</script>\n\n<template>\n <wx-dropdown v-if=\"user !== null\">\n <template #trigger>\n <wx-action :title=\"user.name\">\n <wx-avatar :label=\"initials\" size=\"sm\" />\n </wx-action>\n </template>\n\n <wx-dropdown-item disabled>\n <wx-text size=\"sm\">{{ user.email }}</wx-text>\n </wx-dropdown-item>\n\n <wx-dropdown-item icon=\"logout\" @click=\"auth.logout()\">{{ signOutLabel }}</wx-dropdown-item>\n </wx-dropdown>\n</template>\n","import { h, watch } from 'vue'\nimport type { Admin, AdminPlugin } from '@webx-ui/admin'\nimport LoginCard from './LoginCard.vue'\nimport { createAuthSession, provideAuth } from './session'\n\nexport interface AuthOptions {\n /** Where the sign-in screen lives, inside the panel. */\n path?: string\n /** Props handed to the card — the labels, mostly. */\n card?: Record<string, unknown>\n}\n\n/**\n * Signing in, as a plugin rather than a section: it owns a route and a guard, and it has no\n * place in the menu.\n *\n * Installing it also tells the panel how to find out who is signed in, which is why the panel\n * itself knows nothing about authentication — it holds the answer, not the question.\n */\nexport function auth(options: AuthOptions = {}): AdminPlugin {\n const path = options.path ?? '/login'\n\n return {\n install(admin: Admin) {\n const session = createAuthSession(admin.context)\n\n provideAuth(admin.app, session)\n admin.context.useSessionLoader(() => session.me())\n\n admin.router.addRoute({\n path,\n name: 'webx.login',\n meta: { public: true },\n component: { render: () => h(LoginCard, { ...options.card }) },\n })\n\n admin.router.beforeEach((to) => {\n if (to.meta.public === true) {\n return true\n }\n\n if (admin.context.state.status !== 'unauthenticated') {\n return true\n }\n\n return { path, query: to.fullPath === '/' ? {} : { next: to.fullPath } }\n })\n\n // Both directions are driven by the state rather than by an event, because the card\n // cannot be relied on to announce its own success: signing in flips the panel to\n // `ready`, the shell swaps the branch it renders, and the card is unmounted before the\n // line after `await` runs.\n watch(\n () => admin.context.state.status,\n (status) => {\n const current = admin.router.currentRoute.value\n\n // A session can also end between requests — a sign-out in another tab, an account\n // switched off. The panel learns that from a 401 on whatever it asked for next,\n // which is not a navigation, so nothing would move without this.\n if (status === 'unauthenticated' && current.path !== path) {\n void admin.router.replace({ path, query: { next: current.fullPath } })\n\n return\n }\n\n if (status === 'ready' && current.path === path) {\n const next = current.query.next\n\n void admin.router.replace(typeof next === 'string' ? next : '/')\n }\n },\n )\n },\n }\n}\n\nexport { createAuthSession, provideAuth, useAuth, authKey } from './session'\nexport type { AuthSession, Credentials } from './session'\nexport { default as WxLoginCard } from './LoginCard.vue'\nexport { default as WxUserMenu } from './UserMenu.vue'\n"],"names":["authKey","useAuth","session","inject","createAuthSession","admin","base","error","isUnauthenticated","credentials","body","provideAuth","app","props","__props","emit","__emit","auth","email","ref","password","rememberMe","busy","revealed","capsLock","message","errors","secondsLeft","emailField","useTemplateRef","countdown","onBeforeUnmount","stopCountdown","throttled","computed","throttleNotice","submit","handle","HttpError","startCountdown","seconds","trackCapsLock","event","__expose","_createBlock","_component_wx_card","_createVNode","_component_wx_form","_component_wx_alert","_component_wx_form_item","_component_wx_input","$event","_component_wx_icon","_component_wx_action","_cache","_component_wx_checkbox","_component_wx_button","useAdmin","user","initials","part","_component_wx_dropdown","_component_wx_avatar","_component_wx_dropdown_item","_component_wx_text","_createTextVNode","_toDisplayString","_unref","options","path","h","LoginCard","to","watch","status","current","next"],"mappings":";;AAiBO,MAAMA,2BAA4C,WAAW;AAE7D,SAASC,IAAuB;AACrC,QAAMC,IAAUC,EAAOH,GAAS,IAAI;AAEpC,MAAIE,MAAY;AACd,UAAM,IAAI,MAAM,sEAAsE;AAGxF,SAAOA;AACT;AAQO,SAASE,GAAkBC,GAAkC;AAClE,QAAMC,IAAO,GAAGD,EAAM,OAAO;AAE7B,SAAO;AAAA,IACL,MAAM,KAAK;AACT,UAAI;AAGF,gBAFa,MAAMA,EAAM,KAAK,IAAgC,GAAGC,CAAI,KAAK,GAE9D;AAAA,MACd,SAASC,GAAO;AACd,YAAIC,GAAkBD,CAAK;AACzB,iBAAO;AAGT,cAAMA;AAAA,MACR;AAAA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1B,KAGF,EAAE,MAAAgE,GAAM,OAAOG,EAAG,aAAa,MAAM,CAAA,IAAK,EAAE,MAAMA,EAAG,SAAA,EAAS,CACtE,GAMDC;AAAA,QACE,MAAMpE,EAAM,QAAQ,MAAM;AAAA,QAC1B,CAACqE,MAAW;AACV,gBAAMC,IAAUtE,EAAM,OAAO,aAAa;AAK1C,cAAIqE,MAAW,qBAAqBC,EAAQ,SAASN,GAAM;AACzD,YAAKhE,EAAM,OAAO,QAAQ,EAAE,MAAAgE,GAAM,OAAO,EAAE,MAAMM,EAAQ,SAAA,GAAY;AAErE;AAAA,UACF;AAEA,cAAID,MAAW,WAAWC,EAAQ,SAASN,GAAM;AAC/C,kBAAMO,IAAOD,EAAQ,MAAM;AAE3B,YAAKtE,EAAM,OAAO,QAAQ,OAAOuE,KAAS,WAAWA,IAAO,GAAG;AAAA,UACjE;AAAA,QACF;AAAA,MAAA;AAAA,IAEJ;AAAA,EAAA;AAEJ;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { App, InjectionKey } from 'vue';
|
|
2
|
+
import { AdminContext, AdminUser } from '@webx-ui/admin';
|
|
3
|
+
export interface Credentials {
|
|
4
|
+
email: string;
|
|
5
|
+
password: string;
|
|
6
|
+
remember?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface AuthSession {
|
|
9
|
+
/** Who is signed in, or null. A 401 is an answer, not a failure. */
|
|
10
|
+
me(): Promise<AdminUser | null>;
|
|
11
|
+
/** Signs in and tells the panel to load itself. Throws `HttpError` on a refusal. */
|
|
12
|
+
login(credentials: Credentials): Promise<AdminUser>;
|
|
13
|
+
logout(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export declare const authKey: InjectionKey<AuthSession>;
|
|
16
|
+
export declare function useAuth(): AuthSession;
|
|
17
|
+
/**
|
|
18
|
+
* The three calls `webx-ui/module-auth` answers, and nothing else.
|
|
19
|
+
*
|
|
20
|
+
* The session lives in a cookie, so there is nothing to keep here: the source of truth is the
|
|
21
|
+
* server, and the panel asks it rather than remembering.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createAuthSession(admin: AdminContext): AuthSession;
|
|
24
|
+
export declare function provideAuth(app: App, session: AuthSession): void;
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.wx-login[data-v-b1f8e87b]{width:100%;max-width:26rem}.wx-login__message[data-v-b1f8e87b]{margin-block-end:var(--wx-space-4)}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webx-ui/module-auth",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Signing in to a WebX UI admin panel: the screen, the session and the router guard. Pairs with webx-ui/module-auth on the server.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": [
|
|
8
|
+
"*.css"
|
|
9
|
+
],
|
|
10
|
+
"keywords": [
|
|
11
|
+
"webx-ui",
|
|
12
|
+
"vue",
|
|
13
|
+
"vue3",
|
|
14
|
+
"admin",
|
|
15
|
+
"authentication",
|
|
16
|
+
"laravel"
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/webx-ui/webx-ui.git",
|
|
21
|
+
"directory": "packages/module-auth"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://webx-ui.github.io/webx-ui/guide/roadmap.html",
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"module": "./dist/index.js",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"import": "./dist/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./style.css": "./dist/style.css",
|
|
39
|
+
"./dist/style.css": "./dist/style.css",
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"vue": "^3.5.0",
|
|
44
|
+
"vue-router": "^4.5.0"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@webx-ui/admin": "^0.0.1",
|
|
48
|
+
"@webx-ui/core": "^0.14.1"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "^24.10.1",
|
|
52
|
+
"@vitejs/plugin-vue": "^6.0.1",
|
|
53
|
+
"typescript": "^5.9.3",
|
|
54
|
+
"vite": "^7.1.14",
|
|
55
|
+
"vite-plugin-dts": "^4.5.4",
|
|
56
|
+
"vue": "^3.5.24",
|
|
57
|
+
"vue-router": "^4.5.1",
|
|
58
|
+
"vue-tsc": "^3.1.3"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "vite build",
|
|
62
|
+
"dev": "vite build --watch",
|
|
63
|
+
"typecheck": "vue-tsc -p tsconfig.json --noEmit"
|
|
64
|
+
}
|
|
65
|
+
}
|