@usequeek/theme-kit 0.3.1 → 0.3.2

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.
@@ -97,6 +97,8 @@ export function AuthFlowProvider({ children }: { children: ReactNode }): JSX.Ele
97
97
  const [step, setStep] = useState<AuthStep>('email-otp');
98
98
  const [otp, setOtp] = useState('');
99
99
  const [verifiedToken, setVerifiedToken] = useState(''); // email OTP flow: server-issued token
100
+ // Password sign-up: the address is proven by the same email code first; the typed name/password wait here until it is.
101
+ const [passwordSignup, setPasswordSignup] = useState(false);
100
102
  const [firstName, setFirstName] = useState('');
101
103
  const [lastName, setLastName] = useState('');
102
104
  const [email, setEmail] = useState('');
@@ -146,6 +148,23 @@ export function AuthFlowProvider({ children }: { children: ReactNode }): JSX.Ele
146
148
  }
147
149
  };
148
150
 
151
+ // The proven address is the only way to name an email at register-password: the server refuses a password sign-up without it.
152
+ const registerWithPassword = async (client: ReturnType<typeof getQueekClient>, proof: string): Promise<void> => {
153
+ const res = await client.post<PasswordAuthData>('/client/auth/email/register-password', {
154
+ first_name: firstName.trim(),
155
+ last_name: lastName.trim() || undefined,
156
+ email: email.trim(),
157
+ password,
158
+ phone: '',
159
+ platform: 'client_web',
160
+ verified_token: proof,
161
+ });
162
+ setAuthTokens(res.data.access_token, res.data.refresh_token);
163
+ applyUser(res.data.user);
164
+ setPasswordSignup(false);
165
+ closeModal();
166
+ };
167
+
149
168
  const submitEmailVerifyOtp = async (): Promise<void> => {
150
169
  if (blockPreview()) return;
151
170
  if (otp.length < EMAIL_OTP_LENGTH) return;
@@ -158,12 +177,17 @@ export function AuthFlowProvider({ children }: { children: ReactNode }): JSX.Ele
158
177
  otpCode: otp,
159
178
  });
160
179
  if (data.needs_registration) {
180
+ if (passwordSignup) {
181
+ await registerWithPassword(client, data.verified_token);
182
+ return;
183
+ }
161
184
  setVerifiedToken(data.verified_token);
162
185
  setStep('signup');
163
186
  return;
164
187
  }
165
188
  // tokens already persisted by SDK
166
189
  applyUser(data.user);
190
+ setPasswordSignup(false);
167
191
  closeModal();
168
192
  } catch (err) {
169
193
  setError(mapEmailError(err, t));
@@ -231,17 +255,10 @@ export function AuthFlowProvider({ children }: { children: ReactNode }): JSX.Ele
231
255
  setLoading(true);
232
256
  try {
233
257
  const client = getQueekClient(vendor.slug ?? undefined);
234
- const res = await client.post<PasswordAuthData>('/client/auth/email/register-password', {
235
- first_name: firstName.trim(),
236
- last_name: lastName.trim() || undefined,
237
- email: email.trim(),
238
- password,
239
- phone: '',
240
- platform: 'client_web',
241
- });
242
- setAuthTokens(res.data.access_token, res.data.refresh_token);
243
- applyUser(res.data.user);
244
- closeModal();
258
+ await client.auth.emailRequestOtp({ email: email.trim() });
259
+ setOtp('');
260
+ setPasswordSignup(true);
261
+ setStep('email-otp-verify');
245
262
  } catch (err) {
246
263
  setError(mapEmailError(err, t));
247
264
  } finally {
@@ -291,6 +308,7 @@ export function AuthFlowProvider({ children }: { children: ReactNode }): JSX.Ele
291
308
  setStep('email-otp');
292
309
  setOtp('');
293
310
  setVerifiedToken('');
311
+ setPasswordSignup(false);
294
312
  setFirstName('');
295
313
  setLastName('');
296
314
  setEmail('');
@@ -303,16 +321,19 @@ export function AuthFlowProvider({ children }: { children: ReactNode }): JSX.Ele
303
321
  setStep('email-otp');
304
322
  setOtp('');
305
323
  setVerifiedToken('');
324
+ setPasswordSignup(false);
306
325
  setError(null);
307
326
  };
308
327
 
309
328
  const goToEmailLogin = (): void => {
310
329
  setStep('email-login');
330
+ setPasswordSignup(false);
311
331
  setError(null);
312
332
  };
313
333
 
314
334
  const goToEmailRegister = (): void => {
315
335
  setStep('email-register');
336
+ setPasswordSignup(false);
316
337
  setError(null);
317
338
  };
318
339
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usequeek/theme-kit",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "The runtime a Queek storefront theme is built on: hooks, stores, page renderer, navigation, shared blocks and locale strings.",