@dudousxd/adonis-authkit-react 0.1.2 → 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.
Files changed (38) hide show
  1. package/README.md +26 -0
  2. package/build/index.d.ts +31 -0
  3. package/build/index.js +16 -0
  4. package/build/src/authkit_provider.d.ts +13 -0
  5. package/build/src/authkit_provider.js +11 -0
  6. package/build/src/components/authorized_apps.d.ts +8 -0
  7. package/build/src/components/authorized_apps.js +26 -0
  8. package/build/src/components/avatar.d.ts +22 -0
  9. package/build/src/components/avatar.js +15 -0
  10. package/build/src/components/sign_in_button.d.ts +297 -0
  11. package/build/src/components/sign_in_button.js +16 -0
  12. package/build/src/components/sign_out_button.d.ts +296 -0
  13. package/build/src/components/sign_out_button.js +16 -0
  14. package/build/src/components/user_button.d.ts +8 -0
  15. package/build/src/components/user_button.js +31 -0
  16. package/build/src/components/user_profile.d.ts +6 -0
  17. package/build/src/components/user_profile.js +27 -0
  18. package/build/src/config.d.ts +25 -0
  19. package/build/src/config.js +36 -0
  20. package/build/src/hooks/use_authorized_apps.d.ts +16 -0
  21. package/build/src/hooks/use_authorized_apps.js +15 -0
  22. package/build/src/hooks/use_profile.d.ts +13 -0
  23. package/build/src/hooks/use_profile.js +28 -0
  24. package/build/src/hooks/use_resource.d.ts +11 -0
  25. package/build/src/hooks/use_resource.js +48 -0
  26. package/build/src/hooks/use_sessions.d.ts +16 -0
  27. package/build/src/hooks/use_sessions.js +15 -0
  28. package/build/src/hooks/use_sign_in.d.ts +6 -0
  29. package/build/src/hooks/use_sign_in.js +13 -0
  30. package/build/src/hooks/use_sign_out.d.ts +6 -0
  31. package/build/src/hooks/use_sign_out.js +11 -0
  32. package/build/src/hooks/use_user.d.ts +6 -0
  33. package/build/src/hooks/use_user.js +5 -0
  34. package/build/src/use_auth.js +1 -1
  35. package/build/src/utils.d.ts +2 -0
  36. package/build/src/utils.js +18 -0
  37. package/package.json +5 -3
  38. 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,6 @@
1
+ export interface SignOutOptions {
2
+ returnTo?: string;
3
+ }
4
+ export declare function useSignOut(): {
5
+ signOut: (opts?: SignOutOptions) => void;
6
+ };
@@ -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
+ }
@@ -0,0 +1,6 @@
1
+ import type { AuthUser } from '../types.js';
2
+ export interface UseUserResult {
3
+ user: AuthUser | null;
4
+ isAuthenticated: boolean;
5
+ }
6
+ export declare function useUser(): UseUserResult;
@@ -0,0 +1,5 @@
1
+ import { useAuth } from '../use_auth.js';
2
+ export function useUser() {
3
+ const { user, isAuthenticated } = useAuth();
4
+ return { user, isAuthenticated };
5
+ }
@@ -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(): nenhum <AuthProvider> nem shared-prop `authkit` encontradoretornando estado não-autenticado.');
15
+ console.warn('[authkit] useAuth(): no <AuthProvider> nor shared-prop `authkit` foundreturning unauthenticated state.');
16
16
  }
17
17
  const authkit = resolved ?? UNAUTHENTICATED;
18
18
  return useMemo(() => {
@@ -0,0 +1,2 @@
1
+ export declare function deriveInitials(name?: string | null, email?: string | null): string;
2
+ export declare function currentUrl(): string;
@@ -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.1.2",
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",
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
+ }