@dudousxd/adonis-authkit-react 0.1.1 → 0.2.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/README.md +26 -0
- package/build/index.d.ts +31 -0
- package/build/index.js +16 -0
- package/build/src/authkit_provider.d.ts +13 -0
- package/build/src/authkit_provider.js +11 -0
- package/build/src/components/authorized_apps.d.ts +8 -0
- package/build/src/components/authorized_apps.js +26 -0
- package/build/src/components/avatar.d.ts +22 -0
- package/build/src/components/avatar.js +15 -0
- package/build/src/components/sign_in_button.d.ts +297 -0
- package/build/src/components/sign_in_button.js +16 -0
- package/build/src/components/sign_out_button.d.ts +296 -0
- package/build/src/components/sign_out_button.js +16 -0
- package/build/src/components/user_button.d.ts +8 -0
- package/build/src/components/user_button.js +31 -0
- package/build/src/components/user_profile.d.ts +6 -0
- package/build/src/components/user_profile.js +27 -0
- package/build/src/config.d.ts +25 -0
- package/build/src/config.js +36 -0
- package/build/src/hooks/use_authorized_apps.d.ts +16 -0
- package/build/src/hooks/use_authorized_apps.js +15 -0
- package/build/src/hooks/use_profile.d.ts +13 -0
- package/build/src/hooks/use_profile.js +28 -0
- package/build/src/hooks/use_resource.d.ts +11 -0
- package/build/src/hooks/use_resource.js +48 -0
- package/build/src/hooks/use_sessions.d.ts +16 -0
- package/build/src/hooks/use_sessions.js +15 -0
- package/build/src/hooks/use_sign_in.d.ts +6 -0
- package/build/src/hooks/use_sign_in.js +13 -0
- package/build/src/hooks/use_sign_out.d.ts +6 -0
- package/build/src/hooks/use_sign_out.js +11 -0
- package/build/src/hooks/use_user.d.ts +6 -0
- package/build/src/hooks/use_user.js +5 -0
- package/build/src/use_auth.js +1 -1
- package/build/src/utils.d.ts +2 -0
- package/build/src/utils.js +18 -0
- package/package.json +6 -4
- package/styles.css +189 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useAuthkitConfig, buildAuthUrl } from '../config.js';
|
|
3
|
+
import { currentUrl } from '../utils.js';
|
|
4
|
+
export function useSignIn() {
|
|
5
|
+
const config = useAuthkitConfig();
|
|
6
|
+
const signIn = useCallback((opts) => {
|
|
7
|
+
const returnTo = opts?.returnTo ?? currentUrl();
|
|
8
|
+
const url = buildAuthUrl(config.loginUrl, returnTo);
|
|
9
|
+
if (typeof window !== 'undefined')
|
|
10
|
+
window.location.assign(url);
|
|
11
|
+
}, [config.loginUrl]);
|
|
12
|
+
return { signIn };
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useAuthkitConfig, buildAuthUrl } from '../config.js';
|
|
3
|
+
export function useSignOut() {
|
|
4
|
+
const config = useAuthkitConfig();
|
|
5
|
+
const signOut = useCallback((opts) => {
|
|
6
|
+
const url = buildAuthUrl(config.logoutUrl, opts?.returnTo);
|
|
7
|
+
if (typeof window !== 'undefined')
|
|
8
|
+
window.location.assign(url);
|
|
9
|
+
}, [config.logoutUrl]);
|
|
10
|
+
return { signOut };
|
|
11
|
+
}
|
package/build/src/use_auth.js
CHANGED
|
@@ -12,7 +12,7 @@ export function useAuth() {
|
|
|
12
12
|
const pageProps = usePage().props;
|
|
13
13
|
const resolved = contextValue ?? pageProps?.authkit;
|
|
14
14
|
if (!resolved && typeof process !== 'undefined' && process.env.NODE_ENV !== 'production') {
|
|
15
|
-
console.warn('[authkit] useAuth():
|
|
15
|
+
console.warn('[authkit] useAuth(): no <AuthProvider> nor shared-prop `authkit` found — returning unauthenticated state.');
|
|
16
16
|
}
|
|
17
17
|
const authkit = resolved ?? UNAUTHENTICATED;
|
|
18
18
|
return useMemo(() => {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function deriveInitials(name, email) {
|
|
2
|
+
const source = (name ?? '').trim();
|
|
3
|
+
if (source) {
|
|
4
|
+
const parts = source.split(/\s+/).filter(Boolean);
|
|
5
|
+
if (parts.length === 1)
|
|
6
|
+
return parts[0].slice(0, 2).toUpperCase();
|
|
7
|
+
return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
|
|
8
|
+
}
|
|
9
|
+
const e = (email ?? '').trim();
|
|
10
|
+
if (e)
|
|
11
|
+
return e[0].toUpperCase();
|
|
12
|
+
return '?';
|
|
13
|
+
}
|
|
14
|
+
export function currentUrl() {
|
|
15
|
+
if (typeof window === 'undefined')
|
|
16
|
+
return '';
|
|
17
|
+
return window.location.pathname + window.location.search;
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dudousxd/adonis-authkit-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Frontend ergonomics over AuthKit for AdonisJS + Inertia + React apps: a typed useAuth() hook, role-gating hooks and gating components.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "dudousxd",
|
|
@@ -29,11 +29,13 @@
|
|
|
29
29
|
"main": "./build/index.js",
|
|
30
30
|
"types": "./build/index.d.ts",
|
|
31
31
|
"files": [
|
|
32
|
-
"build"
|
|
32
|
+
"build",
|
|
33
|
+
"styles.css"
|
|
33
34
|
],
|
|
34
35
|
"exports": {
|
|
35
36
|
".": "./build/index.js",
|
|
36
|
-
"./types": "./build/index.js"
|
|
37
|
+
"./types": "./build/index.js",
|
|
38
|
+
"./styles.css": "./styles.css"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
39
41
|
"@inertiajs/react": "3.3.0",
|
|
@@ -41,7 +43,7 @@
|
|
|
41
43
|
"react-dom": "19.2.6"
|
|
42
44
|
},
|
|
43
45
|
"dependencies": {
|
|
44
|
-
"@dudousxd/adonis-authkit-core": "0.
|
|
46
|
+
"@dudousxd/adonis-authkit-core": "0.2.0"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
49
|
"@adonisjs/tsconfig": "2.0.0",
|
package/styles.css
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Estilos prontos dos componentes do @dudousxd/adonis-authkit-react.
|
|
3
|
+
* Temáveis via CSS vars `--authkit-*` (defaults Adonis-violet).
|
|
4
|
+
* Importe em algum ponto da app: `import '@dudousxd/adonis-authkit-react/styles.css'`
|
|
5
|
+
*/
|
|
6
|
+
:root {
|
|
7
|
+
--authkit-primary: #5a45ff;
|
|
8
|
+
--authkit-primary-contrast: #ffffff;
|
|
9
|
+
--authkit-danger: #e5484d;
|
|
10
|
+
--authkit-fg: #1a1523;
|
|
11
|
+
--authkit-muted: #6f6e77;
|
|
12
|
+
--authkit-bg: #ffffff;
|
|
13
|
+
--authkit-border: #e4e2e8;
|
|
14
|
+
--authkit-radius: 8px;
|
|
15
|
+
--authkit-gap: 0.5rem;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.authkit-button {
|
|
19
|
+
display: inline-flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
justify-content: center;
|
|
22
|
+
gap: 0.4rem;
|
|
23
|
+
padding: 0.5rem 0.9rem;
|
|
24
|
+
font: inherit;
|
|
25
|
+
font-weight: 500;
|
|
26
|
+
border-radius: var(--authkit-radius);
|
|
27
|
+
border: 1px solid transparent;
|
|
28
|
+
cursor: pointer;
|
|
29
|
+
line-height: 1.2;
|
|
30
|
+
}
|
|
31
|
+
.authkit-button:disabled {
|
|
32
|
+
opacity: 0.6;
|
|
33
|
+
cursor: not-allowed;
|
|
34
|
+
}
|
|
35
|
+
.authkit-button--primary {
|
|
36
|
+
background: var(--authkit-primary);
|
|
37
|
+
color: var(--authkit-primary-contrast);
|
|
38
|
+
}
|
|
39
|
+
.authkit-button--ghost {
|
|
40
|
+
background: transparent;
|
|
41
|
+
color: var(--authkit-fg);
|
|
42
|
+
border-color: var(--authkit-border);
|
|
43
|
+
}
|
|
44
|
+
.authkit-button--danger {
|
|
45
|
+
background: transparent;
|
|
46
|
+
color: var(--authkit-danger);
|
|
47
|
+
border-color: var(--authkit-border);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.authkit-avatar {
|
|
51
|
+
display: inline-flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
justify-content: center;
|
|
54
|
+
border-radius: 50%;
|
|
55
|
+
background: var(--authkit-primary);
|
|
56
|
+
color: var(--authkit-primary-contrast);
|
|
57
|
+
font-weight: 600;
|
|
58
|
+
font-size: 0.85rem;
|
|
59
|
+
object-fit: cover;
|
|
60
|
+
overflow: hidden;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.authkit-userbutton {
|
|
64
|
+
position: relative;
|
|
65
|
+
display: inline-block;
|
|
66
|
+
}
|
|
67
|
+
.authkit-userbutton__trigger {
|
|
68
|
+
background: none;
|
|
69
|
+
border: none;
|
|
70
|
+
padding: 0;
|
|
71
|
+
cursor: pointer;
|
|
72
|
+
}
|
|
73
|
+
.authkit-userbutton__menu {
|
|
74
|
+
position: absolute;
|
|
75
|
+
right: 0;
|
|
76
|
+
margin-top: 0.4rem;
|
|
77
|
+
min-width: 12rem;
|
|
78
|
+
background: var(--authkit-bg);
|
|
79
|
+
border: 1px solid var(--authkit-border);
|
|
80
|
+
border-radius: var(--authkit-radius);
|
|
81
|
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
|
|
82
|
+
padding: 0.3rem;
|
|
83
|
+
z-index: 50;
|
|
84
|
+
}
|
|
85
|
+
.authkit-userbutton__header {
|
|
86
|
+
padding: 0.5rem 0.6rem;
|
|
87
|
+
border-bottom: 1px solid var(--authkit-border);
|
|
88
|
+
margin-bottom: 0.3rem;
|
|
89
|
+
}
|
|
90
|
+
.authkit-userbutton__name {
|
|
91
|
+
font-weight: 600;
|
|
92
|
+
color: var(--authkit-fg);
|
|
93
|
+
}
|
|
94
|
+
.authkit-userbutton__email {
|
|
95
|
+
font-size: 0.8rem;
|
|
96
|
+
color: var(--authkit-muted);
|
|
97
|
+
}
|
|
98
|
+
.authkit-userbutton__item {
|
|
99
|
+
display: block;
|
|
100
|
+
width: 100%;
|
|
101
|
+
text-align: left;
|
|
102
|
+
padding: 0.5rem 0.6rem;
|
|
103
|
+
background: none;
|
|
104
|
+
border: none;
|
|
105
|
+
border-radius: 6px;
|
|
106
|
+
color: var(--authkit-fg);
|
|
107
|
+
text-decoration: none;
|
|
108
|
+
font: inherit;
|
|
109
|
+
cursor: pointer;
|
|
110
|
+
}
|
|
111
|
+
.authkit-userbutton__item:hover {
|
|
112
|
+
background: rgba(90, 69, 255, 0.08);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.authkit-card {
|
|
116
|
+
background: var(--authkit-bg);
|
|
117
|
+
border: 1px solid var(--authkit-border);
|
|
118
|
+
border-radius: var(--authkit-radius);
|
|
119
|
+
padding: 1rem;
|
|
120
|
+
}
|
|
121
|
+
.authkit-profile__header {
|
|
122
|
+
display: flex;
|
|
123
|
+
align-items: center;
|
|
124
|
+
gap: 0.75rem;
|
|
125
|
+
margin-bottom: 1rem;
|
|
126
|
+
}
|
|
127
|
+
.authkit-profile__name {
|
|
128
|
+
font-weight: 600;
|
|
129
|
+
color: var(--authkit-fg);
|
|
130
|
+
}
|
|
131
|
+
.authkit-profile__email {
|
|
132
|
+
font-size: 0.85rem;
|
|
133
|
+
color: var(--authkit-muted);
|
|
134
|
+
}
|
|
135
|
+
.authkit-profile__form {
|
|
136
|
+
display: flex;
|
|
137
|
+
flex-direction: column;
|
|
138
|
+
gap: var(--authkit-gap);
|
|
139
|
+
}
|
|
140
|
+
.authkit-label {
|
|
141
|
+
font-size: 0.85rem;
|
|
142
|
+
color: var(--authkit-muted);
|
|
143
|
+
}
|
|
144
|
+
.authkit-input {
|
|
145
|
+
padding: 0.5rem 0.6rem;
|
|
146
|
+
border: 1px solid var(--authkit-border);
|
|
147
|
+
border-radius: var(--authkit-radius);
|
|
148
|
+
font: inherit;
|
|
149
|
+
}
|
|
150
|
+
.authkit-error {
|
|
151
|
+
color: var(--authkit-danger);
|
|
152
|
+
font-size: 0.85rem;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.authkit-apps {
|
|
156
|
+
list-style: none;
|
|
157
|
+
margin: 0;
|
|
158
|
+
padding: 0;
|
|
159
|
+
display: flex;
|
|
160
|
+
flex-direction: column;
|
|
161
|
+
gap: var(--authkit-gap);
|
|
162
|
+
}
|
|
163
|
+
.authkit-apps__item {
|
|
164
|
+
display: flex;
|
|
165
|
+
align-items: center;
|
|
166
|
+
justify-content: space-between;
|
|
167
|
+
padding: 0.6rem 0.75rem;
|
|
168
|
+
border: 1px solid var(--authkit-border);
|
|
169
|
+
border-radius: var(--authkit-radius);
|
|
170
|
+
}
|
|
171
|
+
.authkit-apps__info {
|
|
172
|
+
display: flex;
|
|
173
|
+
align-items: center;
|
|
174
|
+
gap: 0.5rem;
|
|
175
|
+
}
|
|
176
|
+
.authkit-apps__logo {
|
|
177
|
+
width: 24px;
|
|
178
|
+
height: 24px;
|
|
179
|
+
border-radius: 4px;
|
|
180
|
+
}
|
|
181
|
+
.authkit-apps__name {
|
|
182
|
+
font-weight: 500;
|
|
183
|
+
color: var(--authkit-fg);
|
|
184
|
+
}
|
|
185
|
+
.authkit-apps__empty,
|
|
186
|
+
.authkit-apps__loading {
|
|
187
|
+
color: var(--authkit-muted);
|
|
188
|
+
font-size: 0.9rem;
|
|
189
|
+
}
|