@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,296 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
export interface SignOutButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick'> {
|
|
3
|
+
children?: ReactNode;
|
|
4
|
+
returnTo?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function SignOutButton({ children, returnTo, className, ...rest }: SignOutButtonProps): import("react").DetailedReactHTMLElement<{
|
|
7
|
+
id?: string | undefined | undefined;
|
|
8
|
+
name?: string | undefined | undefined;
|
|
9
|
+
value?: string | number | readonly string[] | undefined;
|
|
10
|
+
form?: string | undefined | undefined;
|
|
11
|
+
slot?: string | undefined | undefined;
|
|
12
|
+
style?: import("react").CSSProperties | undefined;
|
|
13
|
+
title?: string | undefined | undefined;
|
|
14
|
+
role?: import("react").AriaRole | undefined;
|
|
15
|
+
disabled?: boolean | undefined | undefined;
|
|
16
|
+
formAction?: string | ((formData: FormData) => void | Promise<void>) | undefined;
|
|
17
|
+
formEncType?: string | undefined | undefined;
|
|
18
|
+
formMethod?: string | undefined | undefined;
|
|
19
|
+
formNoValidate?: boolean | undefined | undefined;
|
|
20
|
+
formTarget?: string | undefined | undefined;
|
|
21
|
+
type: string;
|
|
22
|
+
defaultChecked?: boolean | undefined | undefined;
|
|
23
|
+
defaultValue?: string | number | readonly string[] | undefined;
|
|
24
|
+
suppressContentEditableWarning?: boolean | undefined | undefined;
|
|
25
|
+
suppressHydrationWarning?: boolean | undefined | undefined;
|
|
26
|
+
accessKey?: string | undefined | undefined;
|
|
27
|
+
autoCapitalize?: "off" | "none" | "on" | "sentences" | "words" | "characters" | undefined | (string & {}) | undefined;
|
|
28
|
+
autoFocus?: boolean | undefined | undefined;
|
|
29
|
+
contentEditable?: (boolean | "true" | "false") | "inherit" | "plaintext-only" | undefined;
|
|
30
|
+
contextMenu?: string | undefined | undefined;
|
|
31
|
+
dir?: string | undefined | undefined;
|
|
32
|
+
draggable?: (boolean | "true" | "false") | undefined;
|
|
33
|
+
enterKeyHint?: "enter" | "done" | "go" | "next" | "previous" | "search" | "send" | undefined | undefined;
|
|
34
|
+
hidden?: boolean | undefined | undefined;
|
|
35
|
+
lang?: string | undefined | undefined;
|
|
36
|
+
nonce?: string | undefined | undefined;
|
|
37
|
+
spellCheck?: (boolean | "true" | "false") | undefined;
|
|
38
|
+
tabIndex?: number | undefined | undefined;
|
|
39
|
+
translate?: "yes" | "no" | undefined | undefined;
|
|
40
|
+
radioGroup?: string | undefined | undefined;
|
|
41
|
+
about?: string | undefined | undefined;
|
|
42
|
+
content?: string | undefined | undefined;
|
|
43
|
+
datatype?: string | undefined | undefined;
|
|
44
|
+
inlist?: any;
|
|
45
|
+
prefix?: string | undefined | undefined;
|
|
46
|
+
property?: string | undefined | undefined;
|
|
47
|
+
rel?: string | undefined | undefined;
|
|
48
|
+
resource?: string | undefined | undefined;
|
|
49
|
+
rev?: string | undefined | undefined;
|
|
50
|
+
typeof?: string | undefined | undefined;
|
|
51
|
+
vocab?: string | undefined | undefined;
|
|
52
|
+
autoCorrect?: string | undefined | undefined;
|
|
53
|
+
autoSave?: string | undefined | undefined;
|
|
54
|
+
color?: string | undefined | undefined;
|
|
55
|
+
itemProp?: string | undefined | undefined;
|
|
56
|
+
itemScope?: boolean | undefined | undefined;
|
|
57
|
+
itemType?: string | undefined | undefined;
|
|
58
|
+
itemID?: string | undefined | undefined;
|
|
59
|
+
itemRef?: string | undefined | undefined;
|
|
60
|
+
results?: number | undefined | undefined;
|
|
61
|
+
security?: string | undefined | undefined;
|
|
62
|
+
unselectable?: "on" | "off" | undefined | undefined;
|
|
63
|
+
popover?: "" | "auto" | "manual" | "hint" | undefined | undefined;
|
|
64
|
+
popoverTargetAction?: "toggle" | "show" | "hide" | undefined | undefined;
|
|
65
|
+
popoverTarget?: string | undefined | undefined;
|
|
66
|
+
inert?: boolean | undefined | undefined;
|
|
67
|
+
inputMode?: "none" | "text" | "tel" | "url" | "email" | "numeric" | "decimal" | "search" | undefined | undefined;
|
|
68
|
+
is?: string | undefined | undefined;
|
|
69
|
+
exportparts?: string | undefined | undefined;
|
|
70
|
+
part?: string | undefined | undefined;
|
|
71
|
+
"aria-activedescendant"?: string | undefined | undefined;
|
|
72
|
+
"aria-atomic"?: (boolean | "true" | "false") | undefined;
|
|
73
|
+
"aria-autocomplete"?: "none" | "inline" | "list" | "both" | undefined | undefined;
|
|
74
|
+
"aria-braillelabel"?: string | undefined | undefined;
|
|
75
|
+
"aria-brailleroledescription"?: string | undefined | undefined;
|
|
76
|
+
"aria-busy"?: (boolean | "true" | "false") | undefined;
|
|
77
|
+
"aria-checked"?: boolean | "false" | "mixed" | "true" | undefined | undefined;
|
|
78
|
+
"aria-colcount"?: number | undefined | undefined;
|
|
79
|
+
"aria-colindex"?: number | undefined | undefined;
|
|
80
|
+
"aria-colindextext"?: string | undefined | undefined;
|
|
81
|
+
"aria-colspan"?: number | undefined | undefined;
|
|
82
|
+
"aria-controls"?: string | undefined | undefined;
|
|
83
|
+
"aria-current"?: boolean | "false" | "true" | "page" | "step" | "location" | "date" | "time" | undefined | undefined;
|
|
84
|
+
"aria-describedby"?: string | undefined | undefined;
|
|
85
|
+
"aria-description"?: string | undefined | undefined;
|
|
86
|
+
"aria-details"?: string | undefined | undefined;
|
|
87
|
+
"aria-disabled"?: (boolean | "true" | "false") | undefined;
|
|
88
|
+
"aria-dropeffect"?: "none" | "copy" | "execute" | "link" | "move" | "popup" | undefined | undefined;
|
|
89
|
+
"aria-errormessage"?: string | undefined | undefined;
|
|
90
|
+
"aria-expanded"?: (boolean | "true" | "false") | undefined;
|
|
91
|
+
"aria-flowto"?: string | undefined | undefined;
|
|
92
|
+
"aria-grabbed"?: (boolean | "true" | "false") | undefined;
|
|
93
|
+
"aria-haspopup"?: boolean | "false" | "true" | "menu" | "listbox" | "tree" | "grid" | "dialog" | undefined | undefined;
|
|
94
|
+
"aria-hidden"?: (boolean | "true" | "false") | undefined;
|
|
95
|
+
"aria-invalid"?: boolean | "false" | "true" | "grammar" | "spelling" | undefined | undefined;
|
|
96
|
+
"aria-keyshortcuts"?: string | undefined | undefined;
|
|
97
|
+
"aria-label"?: string | undefined | undefined;
|
|
98
|
+
"aria-labelledby"?: string | undefined | undefined;
|
|
99
|
+
"aria-level"?: number | undefined | undefined;
|
|
100
|
+
"aria-live"?: "off" | "assertive" | "polite" | undefined | undefined;
|
|
101
|
+
"aria-modal"?: (boolean | "true" | "false") | undefined;
|
|
102
|
+
"aria-multiline"?: (boolean | "true" | "false") | undefined;
|
|
103
|
+
"aria-multiselectable"?: (boolean | "true" | "false") | undefined;
|
|
104
|
+
"aria-orientation"?: "horizontal" | "vertical" | undefined | undefined;
|
|
105
|
+
"aria-owns"?: string | undefined | undefined;
|
|
106
|
+
"aria-placeholder"?: string | undefined | undefined;
|
|
107
|
+
"aria-posinset"?: number | undefined | undefined;
|
|
108
|
+
"aria-pressed"?: boolean | "false" | "mixed" | "true" | undefined | undefined;
|
|
109
|
+
"aria-readonly"?: (boolean | "true" | "false") | undefined;
|
|
110
|
+
"aria-relevant"?: "additions" | "additions removals" | "additions text" | "all" | "removals" | "removals additions" | "removals text" | "text" | "text additions" | "text removals" | undefined | undefined;
|
|
111
|
+
"aria-required"?: (boolean | "true" | "false") | undefined;
|
|
112
|
+
"aria-roledescription"?: string | undefined | undefined;
|
|
113
|
+
"aria-rowcount"?: number | undefined | undefined;
|
|
114
|
+
"aria-rowindex"?: number | undefined | undefined;
|
|
115
|
+
"aria-rowindextext"?: string | undefined | undefined;
|
|
116
|
+
"aria-rowspan"?: number | undefined | undefined;
|
|
117
|
+
"aria-selected"?: (boolean | "true" | "false") | undefined;
|
|
118
|
+
"aria-setsize"?: number | undefined | undefined;
|
|
119
|
+
"aria-sort"?: "none" | "ascending" | "descending" | "other" | undefined | undefined;
|
|
120
|
+
"aria-valuemax"?: number | undefined | undefined;
|
|
121
|
+
"aria-valuemin"?: number | undefined | undefined;
|
|
122
|
+
"aria-valuenow"?: number | undefined | undefined;
|
|
123
|
+
"aria-valuetext"?: string | undefined | undefined;
|
|
124
|
+
dangerouslySetInnerHTML?: {
|
|
125
|
+
__html: string | TrustedHTML;
|
|
126
|
+
} | undefined | undefined;
|
|
127
|
+
onCopy?: import("react").ClipboardEventHandler<HTMLButtonElement> | undefined;
|
|
128
|
+
onCopyCapture?: import("react").ClipboardEventHandler<HTMLButtonElement> | undefined;
|
|
129
|
+
onCut?: import("react").ClipboardEventHandler<HTMLButtonElement> | undefined;
|
|
130
|
+
onCutCapture?: import("react").ClipboardEventHandler<HTMLButtonElement> | undefined;
|
|
131
|
+
onPaste?: import("react").ClipboardEventHandler<HTMLButtonElement> | undefined;
|
|
132
|
+
onPasteCapture?: import("react").ClipboardEventHandler<HTMLButtonElement> | undefined;
|
|
133
|
+
onCompositionEnd?: import("react").CompositionEventHandler<HTMLButtonElement> | undefined;
|
|
134
|
+
onCompositionEndCapture?: import("react").CompositionEventHandler<HTMLButtonElement> | undefined;
|
|
135
|
+
onCompositionStart?: import("react").CompositionEventHandler<HTMLButtonElement> | undefined;
|
|
136
|
+
onCompositionStartCapture?: import("react").CompositionEventHandler<HTMLButtonElement> | undefined;
|
|
137
|
+
onCompositionUpdate?: import("react").CompositionEventHandler<HTMLButtonElement> | undefined;
|
|
138
|
+
onCompositionUpdateCapture?: import("react").CompositionEventHandler<HTMLButtonElement> | undefined;
|
|
139
|
+
onFocus?: import("react").FocusEventHandler<HTMLButtonElement> | undefined;
|
|
140
|
+
onFocusCapture?: import("react").FocusEventHandler<HTMLButtonElement> | undefined;
|
|
141
|
+
onBlur?: import("react").FocusEventHandler<HTMLButtonElement> | undefined;
|
|
142
|
+
onBlurCapture?: import("react").FocusEventHandler<HTMLButtonElement> | undefined;
|
|
143
|
+
onChange?: import("react").ChangeEventHandler<HTMLButtonElement, Element> | undefined;
|
|
144
|
+
onChangeCapture?: import("react").ChangeEventHandler<HTMLButtonElement, Element> | undefined;
|
|
145
|
+
onBeforeInput?: import("react").InputEventHandler<HTMLButtonElement> | undefined;
|
|
146
|
+
onBeforeInputCapture?: import("react").InputEventHandler<HTMLButtonElement> | undefined;
|
|
147
|
+
onInput?: import("react").InputEventHandler<HTMLButtonElement> | undefined;
|
|
148
|
+
onInputCapture?: import("react").InputEventHandler<HTMLButtonElement> | undefined;
|
|
149
|
+
onReset?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
150
|
+
onResetCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
151
|
+
onSubmit?: import("react").SubmitEventHandler<HTMLButtonElement> | undefined;
|
|
152
|
+
onSubmitCapture?: import("react").SubmitEventHandler<HTMLButtonElement> | undefined;
|
|
153
|
+
onInvalid?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
154
|
+
onInvalidCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
155
|
+
onLoad?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
156
|
+
onLoadCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
157
|
+
onError?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
158
|
+
onErrorCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
159
|
+
onKeyDown?: import("react").KeyboardEventHandler<HTMLButtonElement> | undefined;
|
|
160
|
+
onKeyDownCapture?: import("react").KeyboardEventHandler<HTMLButtonElement> | undefined;
|
|
161
|
+
onKeyPress?: import("react").KeyboardEventHandler<HTMLButtonElement> | undefined;
|
|
162
|
+
onKeyPressCapture?: import("react").KeyboardEventHandler<HTMLButtonElement> | undefined;
|
|
163
|
+
onKeyUp?: import("react").KeyboardEventHandler<HTMLButtonElement> | undefined;
|
|
164
|
+
onKeyUpCapture?: import("react").KeyboardEventHandler<HTMLButtonElement> | undefined;
|
|
165
|
+
onAbort?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
166
|
+
onAbortCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
167
|
+
onCanPlay?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
168
|
+
onCanPlayCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
169
|
+
onCanPlayThrough?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
170
|
+
onCanPlayThroughCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
171
|
+
onDurationChange?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
172
|
+
onDurationChangeCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
173
|
+
onEmptied?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
174
|
+
onEmptiedCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
175
|
+
onEncrypted?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
176
|
+
onEncryptedCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
177
|
+
onEnded?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
178
|
+
onEndedCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
179
|
+
onLoadedData?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
180
|
+
onLoadedDataCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
181
|
+
onLoadedMetadata?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
182
|
+
onLoadedMetadataCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
183
|
+
onLoadStart?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
184
|
+
onLoadStartCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
185
|
+
onPause?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
186
|
+
onPauseCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
187
|
+
onPlay?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
188
|
+
onPlayCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
189
|
+
onPlaying?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
190
|
+
onPlayingCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
191
|
+
onProgress?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
192
|
+
onProgressCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
193
|
+
onRateChange?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
194
|
+
onRateChangeCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
195
|
+
onSeeked?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
196
|
+
onSeekedCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
197
|
+
onSeeking?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
198
|
+
onSeekingCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
199
|
+
onStalled?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
200
|
+
onStalledCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
201
|
+
onSuspend?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
202
|
+
onSuspendCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
203
|
+
onTimeUpdate?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
204
|
+
onTimeUpdateCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
205
|
+
onVolumeChange?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
206
|
+
onVolumeChangeCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
207
|
+
onWaiting?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
208
|
+
onWaitingCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
209
|
+
onAuxClick?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
210
|
+
onAuxClickCapture?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
211
|
+
onClickCapture?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
212
|
+
onContextMenu?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
213
|
+
onContextMenuCapture?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
214
|
+
onDoubleClick?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
215
|
+
onDoubleClickCapture?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
216
|
+
onDrag?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
217
|
+
onDragCapture?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
218
|
+
onDragEnd?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
219
|
+
onDragEndCapture?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
220
|
+
onDragEnter?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
221
|
+
onDragEnterCapture?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
222
|
+
onDragExit?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
223
|
+
onDragExitCapture?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
224
|
+
onDragLeave?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
225
|
+
onDragLeaveCapture?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
226
|
+
onDragOver?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
227
|
+
onDragOverCapture?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
228
|
+
onDragStart?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
229
|
+
onDragStartCapture?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
230
|
+
onDrop?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
231
|
+
onDropCapture?: import("react").DragEventHandler<HTMLButtonElement> | undefined;
|
|
232
|
+
onMouseDown?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
233
|
+
onMouseDownCapture?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
234
|
+
onMouseEnter?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
235
|
+
onMouseLeave?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
236
|
+
onMouseMove?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
237
|
+
onMouseMoveCapture?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
238
|
+
onMouseOut?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
239
|
+
onMouseOutCapture?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
240
|
+
onMouseOver?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
241
|
+
onMouseOverCapture?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
242
|
+
onMouseUp?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
243
|
+
onMouseUpCapture?: import("react").MouseEventHandler<HTMLButtonElement> | undefined;
|
|
244
|
+
onSelect?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
245
|
+
onSelectCapture?: import("react").ReactEventHandler<HTMLButtonElement> | undefined;
|
|
246
|
+
onTouchCancel?: import("react").TouchEventHandler<HTMLButtonElement> | undefined;
|
|
247
|
+
onTouchCancelCapture?: import("react").TouchEventHandler<HTMLButtonElement> | undefined;
|
|
248
|
+
onTouchEnd?: import("react").TouchEventHandler<HTMLButtonElement> | undefined;
|
|
249
|
+
onTouchEndCapture?: import("react").TouchEventHandler<HTMLButtonElement> | undefined;
|
|
250
|
+
onTouchMove?: import("react").TouchEventHandler<HTMLButtonElement> | undefined;
|
|
251
|
+
onTouchMoveCapture?: import("react").TouchEventHandler<HTMLButtonElement> | undefined;
|
|
252
|
+
onTouchStart?: import("react").TouchEventHandler<HTMLButtonElement> | undefined;
|
|
253
|
+
onTouchStartCapture?: import("react").TouchEventHandler<HTMLButtonElement> | undefined;
|
|
254
|
+
onPointerDown?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
255
|
+
onPointerDownCapture?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
256
|
+
onPointerMove?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
257
|
+
onPointerMoveCapture?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
258
|
+
onPointerUp?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
259
|
+
onPointerUpCapture?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
260
|
+
onPointerCancel?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
261
|
+
onPointerCancelCapture?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
262
|
+
onPointerEnter?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
263
|
+
onPointerLeave?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
264
|
+
onPointerOver?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
265
|
+
onPointerOverCapture?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
266
|
+
onPointerOut?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
267
|
+
onPointerOutCapture?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
268
|
+
onGotPointerCapture?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
269
|
+
onGotPointerCaptureCapture?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
270
|
+
onLostPointerCapture?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
271
|
+
onLostPointerCaptureCapture?: import("react").PointerEventHandler<HTMLButtonElement> | undefined;
|
|
272
|
+
onScroll?: import("react").UIEventHandler<HTMLButtonElement> | undefined;
|
|
273
|
+
onScrollCapture?: import("react").UIEventHandler<HTMLButtonElement> | undefined;
|
|
274
|
+
onScrollEnd?: import("react").UIEventHandler<HTMLButtonElement> | undefined;
|
|
275
|
+
onScrollEndCapture?: import("react").UIEventHandler<HTMLButtonElement> | undefined;
|
|
276
|
+
onWheel?: import("react").WheelEventHandler<HTMLButtonElement> | undefined;
|
|
277
|
+
onWheelCapture?: import("react").WheelEventHandler<HTMLButtonElement> | undefined;
|
|
278
|
+
onAnimationStart?: import("react").AnimationEventHandler<HTMLButtonElement> | undefined;
|
|
279
|
+
onAnimationStartCapture?: import("react").AnimationEventHandler<HTMLButtonElement> | undefined;
|
|
280
|
+
onAnimationEnd?: import("react").AnimationEventHandler<HTMLButtonElement> | undefined;
|
|
281
|
+
onAnimationEndCapture?: import("react").AnimationEventHandler<HTMLButtonElement> | undefined;
|
|
282
|
+
onAnimationIteration?: import("react").AnimationEventHandler<HTMLButtonElement> | undefined;
|
|
283
|
+
onAnimationIterationCapture?: import("react").AnimationEventHandler<HTMLButtonElement> | undefined;
|
|
284
|
+
onToggle?: import("react").ToggleEventHandler<HTMLButtonElement> | undefined;
|
|
285
|
+
onBeforeToggle?: import("react").ToggleEventHandler<HTMLButtonElement> | undefined;
|
|
286
|
+
onTransitionCancel?: import("react").TransitionEventHandler<HTMLButtonElement> | undefined;
|
|
287
|
+
onTransitionCancelCapture?: import("react").TransitionEventHandler<HTMLButtonElement> | undefined;
|
|
288
|
+
onTransitionEnd?: import("react").TransitionEventHandler<HTMLButtonElement> | undefined;
|
|
289
|
+
onTransitionEndCapture?: import("react").TransitionEventHandler<HTMLButtonElement> | undefined;
|
|
290
|
+
onTransitionRun?: import("react").TransitionEventHandler<HTMLButtonElement> | undefined;
|
|
291
|
+
onTransitionRunCapture?: import("react").TransitionEventHandler<HTMLButtonElement> | undefined;
|
|
292
|
+
onTransitionStart?: import("react").TransitionEventHandler<HTMLButtonElement> | undefined;
|
|
293
|
+
onTransitionStartCapture?: import("react").TransitionEventHandler<HTMLButtonElement> | undefined;
|
|
294
|
+
className: string;
|
|
295
|
+
onClick: () => void;
|
|
296
|
+
}, HTMLElement> | null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { useSignOut } from '../hooks/use_sign_out.js';
|
|
3
|
+
import { useAuth } from '../use_auth.js';
|
|
4
|
+
export function SignOutButton({ children = 'Sair', returnTo, className, ...rest }) {
|
|
5
|
+
const { signOut } = useSignOut();
|
|
6
|
+
const { isAuthenticated } = useAuth();
|
|
7
|
+
if (!isAuthenticated)
|
|
8
|
+
return null;
|
|
9
|
+
const opts = returnTo ? { returnTo } : undefined;
|
|
10
|
+
return createElement('button', {
|
|
11
|
+
type: 'button',
|
|
12
|
+
className: ['authkit-button', 'authkit-button--ghost', className].filter(Boolean).join(' '),
|
|
13
|
+
onClick: () => signOut(opts),
|
|
14
|
+
...rest,
|
|
15
|
+
}, children);
|
|
16
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface UserButtonProps {
|
|
2
|
+
profileLabel?: string;
|
|
3
|
+
signOutLabel?: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function UserButton({ profileLabel, signOutLabel, className, }: UserButtonProps): import("react").DetailedReactHTMLElement<{
|
|
7
|
+
className: string;
|
|
8
|
+
}, HTMLElement> | null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createElement, useState } from 'react';
|
|
2
|
+
import { useAuth } from '../use_auth.js';
|
|
3
|
+
import { useAuthkitConfig } from '../config.js';
|
|
4
|
+
import { useSignOut } from '../hooks/use_sign_out.js';
|
|
5
|
+
import { Avatar } from './avatar.js';
|
|
6
|
+
export function UserButton({ profileLabel = 'Perfil', signOutLabel = 'Sair', className, }) {
|
|
7
|
+
const { user, isAuthenticated } = useAuth();
|
|
8
|
+
const config = useAuthkitConfig();
|
|
9
|
+
const { signOut } = useSignOut();
|
|
10
|
+
const [open, setOpen] = useState(false);
|
|
11
|
+
if (!isAuthenticated || !user)
|
|
12
|
+
return null;
|
|
13
|
+
const trigger = createElement('button', {
|
|
14
|
+
type: 'button',
|
|
15
|
+
className: 'authkit-userbutton__trigger',
|
|
16
|
+
'aria-haspopup': 'menu',
|
|
17
|
+
'aria-expanded': open,
|
|
18
|
+
onClick: () => setOpen((v) => !v),
|
|
19
|
+
}, createElement(Avatar, { user }));
|
|
20
|
+
const menu = open
|
|
21
|
+
? createElement('div', { className: 'authkit-userbutton__menu', role: 'menu' }, createElement('div', { className: 'authkit-userbutton__header' }, createElement('div', { className: 'authkit-userbutton__name' }, user.name ?? user.email), user.name
|
|
22
|
+
? createElement('div', { className: 'authkit-userbutton__email' }, user.email)
|
|
23
|
+
: null), createElement('a', { className: 'authkit-userbutton__item', role: 'menuitem', href: config.profileUrl }, profileLabel), createElement('button', {
|
|
24
|
+
type: 'button',
|
|
25
|
+
className: 'authkit-userbutton__item',
|
|
26
|
+
role: 'menuitem',
|
|
27
|
+
onClick: () => signOut(),
|
|
28
|
+
}, signOutLabel))
|
|
29
|
+
: null;
|
|
30
|
+
return createElement('div', { className: ['authkit-userbutton', className].filter(Boolean).join(' ') }, trigger, menu);
|
|
31
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createElement, useState } from 'react';
|
|
2
|
+
import { useAuth } from '../use_auth.js';
|
|
3
|
+
import { useProfile } from '../hooks/use_profile.js';
|
|
4
|
+
import { Avatar } from './avatar.js';
|
|
5
|
+
export function UserProfile({ className }) {
|
|
6
|
+
const { user, isAuthenticated } = useAuth();
|
|
7
|
+
const { actions, loading, error } = useProfile();
|
|
8
|
+
const [name, setName] = useState(user?.name ?? '');
|
|
9
|
+
if (!isAuthenticated || !user)
|
|
10
|
+
return null;
|
|
11
|
+
const onSubmit = (e) => {
|
|
12
|
+
e.preventDefault();
|
|
13
|
+
void actions.update({ name });
|
|
14
|
+
};
|
|
15
|
+
return createElement('div', { className: ['authkit-card', 'authkit-profile', className].filter(Boolean).join(' ') }, createElement('div', { className: 'authkit-profile__header' }, createElement(Avatar, { user, size: 56 }), createElement('div', null, createElement('div', { className: 'authkit-profile__name' }, user.name ?? user.email), createElement('div', { className: 'authkit-profile__email' }, user.email))), createElement('form', { className: 'authkit-profile__form', onSubmit }, createElement('label', { className: 'authkit-label', htmlFor: 'authkit-profile-name' }, 'Nome'), createElement('input', {
|
|
16
|
+
id: 'authkit-profile-name',
|
|
17
|
+
className: 'authkit-input',
|
|
18
|
+
value: name,
|
|
19
|
+
onChange: (e) => setName(e.target.value),
|
|
20
|
+
}), error
|
|
21
|
+
? createElement('p', { className: 'authkit-error', role: 'alert' }, error.message)
|
|
22
|
+
: null, createElement('button', {
|
|
23
|
+
type: 'submit',
|
|
24
|
+
className: 'authkit-button authkit-button--primary',
|
|
25
|
+
disabled: loading,
|
|
26
|
+
}, loading ? 'Salvando…' : 'Salvar')));
|
|
27
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface AuthkitEndpoints {
|
|
2
|
+
profile: string;
|
|
3
|
+
sessions: string;
|
|
4
|
+
apps: string;
|
|
5
|
+
passkeys: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AuthkitConfig {
|
|
8
|
+
loginUrl?: string;
|
|
9
|
+
logoutUrl?: string;
|
|
10
|
+
profileUrl?: string;
|
|
11
|
+
endpoints?: Partial<AuthkitEndpoints>;
|
|
12
|
+
csrfToken?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ResolvedAuthkitConfig {
|
|
15
|
+
loginUrl: string;
|
|
16
|
+
logoutUrl: string;
|
|
17
|
+
profileUrl: string;
|
|
18
|
+
endpoints: AuthkitEndpoints;
|
|
19
|
+
csrfToken?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare const DEFAULT_CONFIG: ResolvedAuthkitConfig;
|
|
22
|
+
export declare function resolveConfig(config?: AuthkitConfig): ResolvedAuthkitConfig;
|
|
23
|
+
export declare function buildAuthUrl(base: string, returnTo?: string): string;
|
|
24
|
+
export declare const AuthkitConfigContext: import("react").Context<ResolvedAuthkitConfig>;
|
|
25
|
+
export declare function useAuthkitConfig(): ResolvedAuthkitConfig;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
export const DEFAULT_CONFIG = {
|
|
3
|
+
loginUrl: '/auth/login',
|
|
4
|
+
logoutUrl: '/account/logout',
|
|
5
|
+
profileUrl: '/account/security',
|
|
6
|
+
endpoints: {
|
|
7
|
+
profile: '/account/security/profile',
|
|
8
|
+
sessions: '/account/security',
|
|
9
|
+
apps: '/account/apps',
|
|
10
|
+
passkeys: '/account/mfa/passkeys',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
export function resolveConfig(config) {
|
|
14
|
+
return {
|
|
15
|
+
loginUrl: config?.loginUrl ?? DEFAULT_CONFIG.loginUrl,
|
|
16
|
+
logoutUrl: config?.logoutUrl ?? DEFAULT_CONFIG.logoutUrl,
|
|
17
|
+
profileUrl: config?.profileUrl ?? DEFAULT_CONFIG.profileUrl,
|
|
18
|
+
endpoints: {
|
|
19
|
+
profile: config?.endpoints?.profile ?? DEFAULT_CONFIG.endpoints.profile,
|
|
20
|
+
sessions: config?.endpoints?.sessions ?? DEFAULT_CONFIG.endpoints.sessions,
|
|
21
|
+
apps: config?.endpoints?.apps ?? DEFAULT_CONFIG.endpoints.apps,
|
|
22
|
+
passkeys: config?.endpoints?.passkeys ?? DEFAULT_CONFIG.endpoints.passkeys,
|
|
23
|
+
},
|
|
24
|
+
csrfToken: config?.csrfToken,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function buildAuthUrl(base, returnTo) {
|
|
28
|
+
if (!returnTo)
|
|
29
|
+
return base;
|
|
30
|
+
const sep = base.includes('?') ? '&' : '?';
|
|
31
|
+
return `${base}${sep}returnTo=${encodeURIComponent(returnTo)}`;
|
|
32
|
+
}
|
|
33
|
+
export const AuthkitConfigContext = createContext(DEFAULT_CONFIG);
|
|
34
|
+
export function useAuthkitConfig() {
|
|
35
|
+
return useContext(AuthkitConfigContext);
|
|
36
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ResourceState } from './use_resource.js';
|
|
2
|
+
export interface AuthorizedApp {
|
|
3
|
+
clientId: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
logoUrl?: string;
|
|
6
|
+
scopes?: string[];
|
|
7
|
+
authorizedAt?: string;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface UseAuthorizedAppsResult extends ResourceState<AuthorizedApp[]> {
|
|
11
|
+
actions: {
|
|
12
|
+
refetch(): Promise<void>;
|
|
13
|
+
revoke(clientId: string): Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function useAuthorizedApps(): UseAuthorizedAppsResult;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useAuthkitConfig } from '../config.js';
|
|
3
|
+
import { jsonRequest, useResource } from './use_resource.js';
|
|
4
|
+
export function useAuthorizedApps() {
|
|
5
|
+
const config = useAuthkitConfig();
|
|
6
|
+
const { data, loading, error, refetch } = useResource(config.endpoints.apps, config.csrfToken);
|
|
7
|
+
const revoke = useCallback(async (clientId) => {
|
|
8
|
+
await jsonRequest(`${config.endpoints.apps}/${encodeURIComponent(clientId)}/revoke`, {
|
|
9
|
+
method: 'POST',
|
|
10
|
+
csrfToken: config.csrfToken,
|
|
11
|
+
});
|
|
12
|
+
await refetch();
|
|
13
|
+
}, [config.endpoints.apps, config.csrfToken, refetch]);
|
|
14
|
+
return { data, loading, error, actions: { refetch, revoke } };
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ResourceState } from './use_resource.js';
|
|
2
|
+
import type { AuthUser } from '../types.js';
|
|
3
|
+
export interface ProfileUpdate {
|
|
4
|
+
name?: string;
|
|
5
|
+
avatarUrl?: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface UseProfileResult extends ResourceState<AuthUser> {
|
|
9
|
+
actions: {
|
|
10
|
+
update(data: ProfileUpdate): Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare function useProfile(): UseProfileResult;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
import { useAuthkitConfig } from '../config.js';
|
|
3
|
+
import { useAuth } from '../use_auth.js';
|
|
4
|
+
import { jsonRequest } from './use_resource.js';
|
|
5
|
+
export function useProfile() {
|
|
6
|
+
const config = useAuthkitConfig();
|
|
7
|
+
const { user } = useAuth();
|
|
8
|
+
const [state, setState] = useState({
|
|
9
|
+
data: user,
|
|
10
|
+
loading: false,
|
|
11
|
+
error: null,
|
|
12
|
+
});
|
|
13
|
+
const update = useCallback(async (data) => {
|
|
14
|
+
setState((s) => ({ ...s, loading: true, error: null }));
|
|
15
|
+
try {
|
|
16
|
+
const updated = await jsonRequest(config.endpoints.profile, {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
body: JSON.stringify(data),
|
|
19
|
+
csrfToken: config.csrfToken,
|
|
20
|
+
});
|
|
21
|
+
setState({ data: updated ?? { ...user, ...data }, loading: false, error: null });
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
setState((s) => ({ ...s, loading: false, error: err }));
|
|
25
|
+
}
|
|
26
|
+
}, [config.endpoints.profile, config.csrfToken, user]);
|
|
27
|
+
return { ...state, actions: { update } };
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ResourceState<T> {
|
|
2
|
+
data: T | null;
|
|
3
|
+
loading: boolean;
|
|
4
|
+
error: Error | null;
|
|
5
|
+
}
|
|
6
|
+
export declare function jsonRequest<T>(url: string, init?: RequestInit & {
|
|
7
|
+
csrfToken?: string;
|
|
8
|
+
}): Promise<T>;
|
|
9
|
+
export declare function useResource<T>(url: string, csrfToken?: string): ResourceState<T> & {
|
|
10
|
+
refetch: () => Promise<void>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
export async function jsonRequest(url, init = {}) {
|
|
3
|
+
const { csrfToken, headers, ...rest } = init;
|
|
4
|
+
const res = await fetch(url, {
|
|
5
|
+
credentials: 'same-origin',
|
|
6
|
+
headers: {
|
|
7
|
+
'Accept': 'application/json',
|
|
8
|
+
...(rest.body ? { 'Content-Type': 'application/json' } : {}),
|
|
9
|
+
...(csrfToken ? { 'X-CSRF-TOKEN': csrfToken } : {}),
|
|
10
|
+
...headers,
|
|
11
|
+
},
|
|
12
|
+
...rest,
|
|
13
|
+
});
|
|
14
|
+
if (!res.ok) {
|
|
15
|
+
let message = `Request failed (${res.status})`;
|
|
16
|
+
try {
|
|
17
|
+
const body = await res.json();
|
|
18
|
+
if (body && typeof body.message === 'string')
|
|
19
|
+
message = body.message;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
}
|
|
23
|
+
throw new Error(message);
|
|
24
|
+
}
|
|
25
|
+
const text = await res.text();
|
|
26
|
+
return (text ? JSON.parse(text) : null);
|
|
27
|
+
}
|
|
28
|
+
export function useResource(url, csrfToken) {
|
|
29
|
+
const [state, setState] = useState({
|
|
30
|
+
data: null,
|
|
31
|
+
loading: true,
|
|
32
|
+
error: null,
|
|
33
|
+
});
|
|
34
|
+
const refetch = useCallback(async () => {
|
|
35
|
+
setState((s) => ({ ...s, loading: true, error: null }));
|
|
36
|
+
try {
|
|
37
|
+
const data = await jsonRequest(url, { csrfToken });
|
|
38
|
+
setState({ data, loading: false, error: null });
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
setState({ data: null, loading: false, error: err });
|
|
42
|
+
}
|
|
43
|
+
}, [url, csrfToken]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
void refetch();
|
|
46
|
+
}, [refetch]);
|
|
47
|
+
return { ...state, refetch };
|
|
48
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ResourceState } from './use_resource.js';
|
|
2
|
+
export interface AuthSession {
|
|
3
|
+
id: string;
|
|
4
|
+
device?: string;
|
|
5
|
+
ip?: string;
|
|
6
|
+
lastSeenAt?: string;
|
|
7
|
+
current?: boolean;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface UseSessionsResult extends ResourceState<AuthSession[]> {
|
|
11
|
+
actions: {
|
|
12
|
+
refetch(): Promise<void>;
|
|
13
|
+
revoke(id: string): Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function useSessions(): UseSessionsResult;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useAuthkitConfig } from '../config.js';
|
|
3
|
+
import { jsonRequest, useResource } from './use_resource.js';
|
|
4
|
+
export function useSessions() {
|
|
5
|
+
const config = useAuthkitConfig();
|
|
6
|
+
const { data, loading, error, refetch } = useResource(config.endpoints.sessions, config.csrfToken);
|
|
7
|
+
const revoke = useCallback(async (id) => {
|
|
8
|
+
await jsonRequest(`${config.endpoints.sessions}/${encodeURIComponent(id)}/revoke`, {
|
|
9
|
+
method: 'POST',
|
|
10
|
+
csrfToken: config.csrfToken,
|
|
11
|
+
});
|
|
12
|
+
await refetch();
|
|
13
|
+
}, [config.endpoints.sessions, config.csrfToken, refetch]);
|
|
14
|
+
return { data, loading, error, actions: { refetch, revoke } };
|
|
15
|
+
}
|