@sparkstudio/authentication-ui 1.0.28 → 1.0.30

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/dist/index.cjs CHANGED
@@ -177,7 +177,10 @@ function UserProvider({
177
177
  }) {
178
178
  const [user, setUserState] = (0, import_react.useState)(null);
179
179
  const [isLoading, setIsLoading] = (0, import_react.useState)(true);
180
+ const hasFetchedRef = (0, import_react.useRef)(false);
180
181
  (0, import_react.useEffect)(() => {
182
+ if (hasFetchedRef.current) return;
183
+ hasFetchedRef.current = true;
181
184
  const fetchUser = async () => {
182
185
  setIsLoading(true);
183
186
  try {
@@ -189,20 +192,19 @@ function UserProvider({
189
192
  localStorage.setItem("auth_token", authResponseDTO?.Token ?? "");
190
193
  const user2 = authResponseDTO?.User ?? null;
191
194
  setUser(user2);
192
- onLoginSuccess?.(user2);
193
195
  } else {
194
196
  throw new Error("Authenticated user in cache does not exist.");
195
197
  }
196
198
  } catch (error) {
197
199
  console.warn("No user logged in", error);
198
- setUserState(null);
200
+ setUser(null);
199
201
  onLoginFailed?.(error);
200
202
  } finally {
201
203
  setIsLoading(false);
202
204
  }
203
205
  };
204
206
  fetchUser();
205
- }, [authenticationUrl]);
207
+ }, [authenticationUrl, accountsUrl]);
206
208
  const setUser = (user2) => {
207
209
  setUserState(user2);
208
210
  if (user2) {
@@ -222,7 +224,8 @@ function UserProvider({
222
224
  );
223
225
  onLogoutFailed?.(err);
224
226
  }
225
- setUserState(null);
227
+ setUser(null);
228
+ setIsLoading(false);
226
229
  };
227
230
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
228
231
  UserContext.Provider,
@@ -279,8 +282,9 @@ var import_common_ui = require("@sparkstudio/common-ui");
279
282
  var import_accounts_sdk2 = require("@sparkstudio/accounts-sdk");
280
283
  var import_jsx_runtime3 = require("react/jsx-runtime");
281
284
  function LoginButton({ onLogin, onLoginFailed }) {
282
- const { setUser, authenticationUrl, accountsUrl } = useUser();
283
- const [loading, setLoading] = (0, import_react2.useState)(false);
285
+ const { setUser, authenticationUrl, accountsUrl, isLoading } = useUser();
286
+ const [buttonLoading, setButtonLoading] = (0, import_react2.useState)(false);
287
+ const loading = isLoading || buttonLoading;
284
288
  const login = (0, import_google2.useGoogleLogin)({
285
289
  flow: "implicit",
286
290
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -301,29 +305,29 @@ function LoginButton({ onLogin, onLoginFailed }) {
301
305
  console.error("\u{1F534} Login failed (Google or backend SignIn)", error);
302
306
  onLoginFailed?.(error);
303
307
  } finally {
304
- setLoading(false);
308
+ setButtonLoading(false);
305
309
  }
306
310
  },
307
311
  onError: (error) => {
308
312
  console.error("\u274C Google OAuth Login Failed", error);
309
313
  onLoginFailed?.(error);
310
- setLoading(false);
314
+ setButtonLoading(false);
311
315
  },
312
316
  onNonOAuthError: (nonOAuthError) => {
313
317
  console.error("\u26A0\uFE0F Google Non-OAuth error", nonOAuthError);
314
318
  onLoginFailed?.(nonOAuthError);
315
- setLoading(false);
319
+ setButtonLoading(false);
316
320
  }
317
321
  });
318
322
  const handleClick = () => {
319
323
  if (loading) return;
320
- setLoading(true);
324
+ setButtonLoading(true);
321
325
  try {
322
326
  login();
323
327
  } catch (err) {
324
328
  console.error("Error starting Google login", err);
325
329
  onLoginFailed?.(err);
326
- setLoading(false);
330
+ setButtonLoading(false);
327
331
  }
328
332
  };
329
333
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_common_ui.Button, { onClick: handleClick, disabled: loading, children: loading ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
@@ -342,7 +346,8 @@ function LoginButton({ onLogin, onLoginFailed }) {
342
346
  {
343
347
  src: "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3c/Google_Favicon_2025.svg/960px-Google_Favicon_2025.svg.png",
344
348
  alt: "Google",
345
- style: { width: "21px", height: "21px", margin: 0, padding: 0 }
349
+ style: { width: "21px", height: "21px", margin: 0, padding: 0 },
350
+ className: "rounded-circle"
346
351
  }
347
352
  ),
348
353
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "d-none d-sm-inline ms-2", children: "Login" })
@@ -374,7 +379,8 @@ function UserInfoCard({ onLogin, onLogout, onLoginFailed }) {
374
379
  {
375
380
  src: user.ProfilePicture,
376
381
  alt: "Profile",
377
- style: { width: "21px", height: "21px", margin: 0, padding: 0 }
382
+ style: { width: "21px", height: "21px", margin: 0, padding: 0 },
383
+ className: "rounded-circle"
378
384
  }
379
385
  ),
380
386
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "d-none d-sm-inline ms-2", children: "Logout" })
package/dist/index.js CHANGED
@@ -127,9 +127,12 @@ import {
127
127
  createContext,
128
128
  useContext,
129
129
  useState,
130
- useEffect
130
+ useEffect,
131
+ useRef
131
132
  } from "react";
132
- import { SparkStudioAccountsSDK } from "@sparkstudio/accounts-sdk";
133
+ import {
134
+ SparkStudioAccountsSDK
135
+ } from "@sparkstudio/accounts-sdk";
133
136
  import { jsx } from "react/jsx-runtime";
134
137
  var UserContext = createContext(void 0);
135
138
  function UserProvider({
@@ -143,7 +146,10 @@ function UserProvider({
143
146
  }) {
144
147
  const [user, setUserState] = useState(null);
145
148
  const [isLoading, setIsLoading] = useState(true);
149
+ const hasFetchedRef = useRef(false);
146
150
  useEffect(() => {
151
+ if (hasFetchedRef.current) return;
152
+ hasFetchedRef.current = true;
147
153
  const fetchUser = async () => {
148
154
  setIsLoading(true);
149
155
  try {
@@ -155,20 +161,19 @@ function UserProvider({
155
161
  localStorage.setItem("auth_token", authResponseDTO?.Token ?? "");
156
162
  const user2 = authResponseDTO?.User ?? null;
157
163
  setUser(user2);
158
- onLoginSuccess?.(user2);
159
164
  } else {
160
165
  throw new Error("Authenticated user in cache does not exist.");
161
166
  }
162
167
  } catch (error) {
163
168
  console.warn("No user logged in", error);
164
- setUserState(null);
169
+ setUser(null);
165
170
  onLoginFailed?.(error);
166
171
  } finally {
167
172
  setIsLoading(false);
168
173
  }
169
174
  };
170
175
  fetchUser();
171
- }, [authenticationUrl]);
176
+ }, [authenticationUrl, accountsUrl]);
172
177
  const setUser = (user2) => {
173
178
  setUserState(user2);
174
179
  if (user2) {
@@ -188,7 +193,8 @@ function UserProvider({
188
193
  );
189
194
  onLogoutFailed?.(err);
190
195
  }
191
- setUserState(null);
196
+ setUser(null);
197
+ setIsLoading(false);
192
198
  };
193
199
  return /* @__PURE__ */ jsx(
194
200
  UserContext.Provider,
@@ -242,11 +248,14 @@ function AuthenticatorProvider({
242
248
  import { useState as useState2 } from "react";
243
249
  import { useGoogleLogin } from "@react-oauth/google";
244
250
  import { Button } from "@sparkstudio/common-ui";
245
- import { SparkStudioAccountsSDK as SparkStudioAccountsSDK2 } from "@sparkstudio/accounts-sdk";
251
+ import {
252
+ SparkStudioAccountsSDK as SparkStudioAccountsSDK2
253
+ } from "@sparkstudio/accounts-sdk";
246
254
  import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
247
255
  function LoginButton({ onLogin, onLoginFailed }) {
248
- const { setUser, authenticationUrl, accountsUrl } = useUser();
249
- const [loading, setLoading] = useState2(false);
256
+ const { setUser, authenticationUrl, accountsUrl, isLoading } = useUser();
257
+ const [buttonLoading, setButtonLoading] = useState2(false);
258
+ const loading = isLoading || buttonLoading;
250
259
  const login = useGoogleLogin({
251
260
  flow: "implicit",
252
261
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -267,29 +276,29 @@ function LoginButton({ onLogin, onLoginFailed }) {
267
276
  console.error("\u{1F534} Login failed (Google or backend SignIn)", error);
268
277
  onLoginFailed?.(error);
269
278
  } finally {
270
- setLoading(false);
279
+ setButtonLoading(false);
271
280
  }
272
281
  },
273
282
  onError: (error) => {
274
283
  console.error("\u274C Google OAuth Login Failed", error);
275
284
  onLoginFailed?.(error);
276
- setLoading(false);
285
+ setButtonLoading(false);
277
286
  },
278
287
  onNonOAuthError: (nonOAuthError) => {
279
288
  console.error("\u26A0\uFE0F Google Non-OAuth error", nonOAuthError);
280
289
  onLoginFailed?.(nonOAuthError);
281
- setLoading(false);
290
+ setButtonLoading(false);
282
291
  }
283
292
  });
284
293
  const handleClick = () => {
285
294
  if (loading) return;
286
- setLoading(true);
295
+ setButtonLoading(true);
287
296
  try {
288
297
  login();
289
298
  } catch (err) {
290
299
  console.error("Error starting Google login", err);
291
300
  onLoginFailed?.(err);
292
- setLoading(false);
301
+ setButtonLoading(false);
293
302
  }
294
303
  };
295
304
  return /* @__PURE__ */ jsx3(Button, { onClick: handleClick, disabled: loading, children: loading ? /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -308,7 +317,8 @@ function LoginButton({ onLogin, onLoginFailed }) {
308
317
  {
309
318
  src: "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3c/Google_Favicon_2025.svg/960px-Google_Favicon_2025.svg.png",
310
319
  alt: "Google",
311
- style: { width: "21px", height: "21px", margin: 0, padding: 0 }
320
+ style: { width: "21px", height: "21px", margin: 0, padding: 0 },
321
+ className: "rounded-circle"
312
322
  }
313
323
  ),
314
324
  /* @__PURE__ */ jsx3("span", { className: "d-none d-sm-inline ms-2", children: "Login" })
@@ -340,7 +350,8 @@ function UserInfoCard({ onLogin, onLogout, onLoginFailed }) {
340
350
  {
341
351
  src: user.ProfilePicture,
342
352
  alt: "Profile",
343
- style: { width: "21px", height: "21px", margin: 0, padding: 0 }
353
+ style: { width: "21px", height: "21px", margin: 0, padding: 0 },
354
+ className: "rounded-circle"
344
355
  }
345
356
  ),
346
357
  /* @__PURE__ */ jsx4("span", { className: "d-none d-sm-inline ms-2", children: "Logout" })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkstudio/authentication-ui",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -37,8 +37,8 @@
37
37
  "dependencies": {
38
38
  "@react-oauth/google": "^0.13.4",
39
39
  "@sparkstudio/accounts-sdk": "^1.1.73",
40
- "@sparkstudio/accounts-ui": "^1.1.73",
41
- "@sparkstudio/common-ui": "^1.0.5",
40
+ "@sparkstudio/accounts-ui": "^1.1.78",
41
+ "@sparkstudio/common-ui": "^1.0.29",
42
42
  "rimraf": "^6.1.2"
43
43
  },
44
44
  "devDependencies": {