talizen 0.2.15 → 0.2.16
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 +3 -7
- package/auth.d.ts +0 -2
- package/auth.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -115,9 +115,7 @@ When a `File` object appears in the payload, `submitForm()` will:
|
|
|
115
115
|
import {
|
|
116
116
|
currentUser,
|
|
117
117
|
listAuthProviders,
|
|
118
|
-
login,
|
|
119
118
|
loginWithOAuth,
|
|
120
|
-
logout,
|
|
121
119
|
register,
|
|
122
120
|
updateProfile,
|
|
123
121
|
useAuth,
|
|
@@ -129,13 +127,11 @@ await register({
|
|
|
129
127
|
name: "Alice",
|
|
130
128
|
email: "hi@talizen.com",
|
|
131
129
|
});
|
|
132
|
-
await login({ account: "alice", password: "secret" });
|
|
133
130
|
|
|
134
131
|
const user = await currentUser();
|
|
135
132
|
await updateProfile({
|
|
136
133
|
address: "No. 1 Example Road",
|
|
137
134
|
});
|
|
138
|
-
await logout();
|
|
139
135
|
|
|
140
136
|
const providers = await listAuthProviders();
|
|
141
137
|
console.log(providers.map((provider) => provider.key));
|
|
@@ -143,9 +139,9 @@ console.log(providers.map((provider) => provider.key));
|
|
|
143
139
|
await loginWithOAuth("github", { redirectUrl: "/account" });
|
|
144
140
|
|
|
145
141
|
function AccountBadge() {
|
|
146
|
-
const { user, loading, logout } = useAuth();
|
|
142
|
+
const { user, loading, login, logout } = useAuth();
|
|
147
143
|
if (loading) return <span>Loading...</span>;
|
|
148
|
-
if (!user) return <
|
|
144
|
+
if (!user) return <button onClick={() => login("alice", "secret")}>Sign in</button>;
|
|
149
145
|
return <button onClick={() => logout()}>{user.name ?? user.account ?? "Logout"}</button>;
|
|
150
146
|
}
|
|
151
147
|
```
|
|
@@ -231,7 +227,7 @@ Func HTTP responses use the HTTP status code rather than a top-level `ok` field.
|
|
|
231
227
|
## Package Layout
|
|
232
228
|
|
|
233
229
|
- `talizen/core`: shared runtime config, request helpers, and base data types.
|
|
234
|
-
- `talizen/auth`: project user register,
|
|
230
|
+
- `talizen/auth`: project user register, current user helpers, and the React `useAuth()` state hook for login/logout flows.
|
|
235
231
|
- `talizen/cms`: CMS content types and content query APIs.
|
|
236
232
|
- `talizen/form`: form submission helpers and related types.
|
|
237
233
|
- `talizen/func`: custom function invocation helpers such as `invoke`.
|
package/auth.d.ts
CHANGED
|
@@ -54,7 +54,6 @@ export declare class TalizenAuthError extends Error {
|
|
|
54
54
|
constructor(message: string);
|
|
55
55
|
}
|
|
56
56
|
export declare function register(input: AuthRegisterInput, options?: TalizenRequestOptions): Promise<AuthUser>;
|
|
57
|
-
export declare function login(input: AuthPasswordInput, options?: TalizenRequestOptions): Promise<AuthUser>;
|
|
58
57
|
export interface UseAuthResult {
|
|
59
58
|
user: AuthUser | null;
|
|
60
59
|
loading: boolean;
|
|
@@ -76,7 +75,6 @@ export interface UseAuthResult {
|
|
|
76
75
|
* config, which lets preview auth headers update the page without remounting.
|
|
77
76
|
*/
|
|
78
77
|
export declare function useAuth(options?: TalizenRequestOptions): UseAuthResult;
|
|
79
|
-
export declare function logout(options?: TalizenRequestOptions): Promise<void>;
|
|
80
78
|
export declare function currentUser(options?: TalizenRequestOptions): Promise<AuthUser | null>;
|
|
81
79
|
export declare function updateProfile(profile: AuthProfile, options?: TalizenRequestOptions): Promise<AuthUser>;
|
|
82
80
|
export declare function requireUser(options?: TalizenRequestOptions): Promise<AuthUser>;
|
package/auth.js
CHANGED
|
@@ -12,7 +12,7 @@ export async function register(input, options) {
|
|
|
12
12
|
body: JSON.stringify(input),
|
|
13
13
|
}, options);
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
async function loginRequest(input, options) {
|
|
16
16
|
return requestJson("/auth/login", {
|
|
17
17
|
method: "POST",
|
|
18
18
|
body: JSON.stringify(input),
|
|
@@ -135,7 +135,7 @@ export function useAuth(options) {
|
|
|
135
135
|
void refresh().catch(() => { });
|
|
136
136
|
}, [refresh]);
|
|
137
137
|
const loginAndRefresh = React.useCallback(async (input, password) => {
|
|
138
|
-
const nextUser = await
|
|
138
|
+
const nextUser = await loginRequest(normalizeLoginInput(input, password), optionsRef.current);
|
|
139
139
|
setAuthUser(nextUser);
|
|
140
140
|
return nextUser;
|
|
141
141
|
}, []);
|
|
@@ -145,7 +145,7 @@ export function useAuth(options) {
|
|
|
145
145
|
return nextUser;
|
|
146
146
|
}, []);
|
|
147
147
|
const logoutAndRefresh = React.useCallback(async () => {
|
|
148
|
-
await
|
|
148
|
+
await logoutRequest(optionsRef.current);
|
|
149
149
|
setAuthUser(null);
|
|
150
150
|
}, []);
|
|
151
151
|
const updateProfileAndRefresh = React.useCallback(async (profile) => {
|
|
@@ -162,7 +162,7 @@ export function useAuth(options) {
|
|
|
162
162
|
updateProfile: updateProfileAndRefresh,
|
|
163
163
|
};
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
async function logoutRequest(options) {
|
|
166
166
|
await requestJson("/auth/logout", {
|
|
167
167
|
method: "POST",
|
|
168
168
|
body: JSON.stringify({}),
|