talizen 0.2.16 → 0.2.17

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 CHANGED
@@ -111,38 +111,29 @@ When a `File` object appears in the payload, `submitForm()` will:
111
111
 
112
112
  ### Login users
113
113
 
114
- ```ts
114
+ ```tsx
115
115
  import {
116
- currentUser,
117
116
  listAuthProviders,
118
117
  loginWithOAuth,
119
- register,
120
- updateProfile,
121
118
  useAuth,
122
119
  } from "talizen/auth";
123
120
 
124
- await register({
125
- account: "alice",
126
- password: "secret",
127
- name: "Alice",
128
- email: "hi@talizen.com",
129
- });
130
-
131
- const user = await currentUser();
132
- await updateProfile({
133
- address: "No. 1 Example Road",
134
- });
135
-
136
121
  const providers = await listAuthProviders();
137
122
  console.log(providers.map((provider) => provider.key));
138
123
 
139
124
  await loginWithOAuth("github", { redirectUrl: "/account" });
140
125
 
141
126
  function AccountBadge() {
142
- const { user, loading, login, logout } = useAuth();
127
+ const { user, loading, login, register, logout, updateProfile } = useAuth();
143
128
  if (loading) return <span>Loading...</span>;
144
129
  if (!user) return <button onClick={() => login("alice", "secret")}>Sign in</button>;
145
- return <button onClick={() => logout()}>{user.name ?? user.account ?? "Logout"}</button>;
130
+ return (
131
+ <div>
132
+ <button onClick={() => register("bob", "secret", "Bob")}>Create account</button>
133
+ <button onClick={() => updateProfile({ address: "No. 1 Example Road" })}>Update profile</button>
134
+ <button onClick={() => logout()}>{user.name ?? user.account ?? "Logout"}</button>
135
+ </div>
136
+ );
146
137
  }
147
138
  ```
148
139
 
package/auth.d.ts CHANGED
@@ -75,9 +75,7 @@ export interface UseAuthResult {
75
75
  * config, which lets preview auth headers update the page without remounting.
76
76
  */
77
77
  export declare function useAuth(options?: TalizenRequestOptions): UseAuthResult;
78
- export declare function currentUser(options?: TalizenRequestOptions): Promise<AuthUser | null>;
79
78
  export declare function updateProfile(profile: AuthProfile, options?: TalizenRequestOptions): Promise<AuthUser>;
80
- export declare function requireUser(options?: TalizenRequestOptions): Promise<AuthUser>;
81
79
  export declare function listAuthProviders(options?: TalizenRequestOptions): Promise<AuthProvider[]>;
82
80
  export declare function getOAuthLoginUrl(provider: string, options?: AuthOAuthLoginURLOptions): Promise<string>;
83
81
  export declare function loginWithOAuth(provider: string, options?: AuthOAuthLoginURLOptions): Promise<void>;
package/auth.js CHANGED
@@ -83,7 +83,7 @@ async function refreshAuthState(options) {
83
83
  authErrorState = null;
84
84
  emitAuthChange();
85
85
  try {
86
- const user = await currentUser(options);
86
+ const user = await fetchCurrentUser(options);
87
87
  if (authRequestId === requestId) {
88
88
  currentUserState = user;
89
89
  authErrorState = null;
@@ -168,7 +168,7 @@ async function logoutRequest(options) {
168
168
  body: JSON.stringify({}),
169
169
  }, options);
170
170
  }
171
- export async function currentUser(options) {
171
+ async function fetchCurrentUser(options) {
172
172
  return requestJson("/auth/me", { method: "GET" }, options);
173
173
  }
174
174
  export async function updateProfile(profile, options) {
@@ -177,13 +177,6 @@ export async function updateProfile(profile, options) {
177
177
  body: JSON.stringify({ profile }),
178
178
  }, options);
179
179
  }
180
- export async function requireUser(options) {
181
- const user = await currentUser(options);
182
- if (!user) {
183
- throw new TalizenAuthError("Login required.");
184
- }
185
- return user;
186
- }
187
180
  export async function listAuthProviders(options) {
188
181
  const response = await requestJson("/auth/provider_list", { method: "GET" }, options);
189
182
  return response.list ?? [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "talizen",
3
- "version": "0.2.16",
3
+ "version": "0.2.17",
4
4
  "description": "Talizen frontend SDK types for cms, form and core.",
5
5
  "type": "module",
6
6
  "license": "MIT",