@sparkstudio/authentication-ui 1.0.2 → 1.0.4

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
@@ -1362,7 +1362,7 @@ var require_react_development = __commonJS({
1362
1362
  }
1363
1363
  return dispatcher.useContext(Context);
1364
1364
  }
1365
- function useState2(initialState) {
1365
+ function useState3(initialState) {
1366
1366
  var dispatcher = resolveDispatcher();
1367
1367
  return dispatcher.useState(initialState);
1368
1368
  }
@@ -1370,7 +1370,7 @@ var require_react_development = __commonJS({
1370
1370
  var dispatcher = resolveDispatcher();
1371
1371
  return dispatcher.useReducer(reducer, initialArg, init);
1372
1372
  }
1373
- function useRef2(initialValue) {
1373
+ function useRef(initialValue) {
1374
1374
  var dispatcher = resolveDispatcher();
1375
1375
  return dispatcher.useRef(initialValue);
1376
1376
  }
@@ -2164,8 +2164,8 @@ var require_react_development = __commonJS({
2164
2164
  exports2.useLayoutEffect = useLayoutEffect;
2165
2165
  exports2.useMemo = useMemo;
2166
2166
  exports2.useReducer = useReducer;
2167
- exports2.useRef = useRef2;
2168
- exports2.useState = useState2;
2167
+ exports2.useRef = useRef;
2168
+ exports2.useState = useState3;
2169
2169
  exports2.useSyncExternalStore = useSyncExternalStore;
2170
2170
  exports2.useTransition = useTransition;
2171
2171
  exports2.version = ReactVersion;
@@ -2221,7 +2221,7 @@ var require_react_jsx_runtime_development = __commonJS({
2221
2221
  if (process.env.NODE_ENV !== "production") {
2222
2222
  (function() {
2223
2223
  "use strict";
2224
- var React5 = require_react();
2224
+ var React = require_react();
2225
2225
  var REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol.for("react.element");
2226
2226
  var REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for("react.portal");
2227
2227
  var REACT_FRAGMENT_TYPE = /* @__PURE__ */ Symbol.for("react.fragment");
@@ -2247,7 +2247,7 @@ var require_react_jsx_runtime_development = __commonJS({
2247
2247
  }
2248
2248
  return null;
2249
2249
  }
2250
- var ReactSharedInternals = React5.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2250
+ var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2251
2251
  function error(format) {
2252
2252
  {
2253
2253
  {
@@ -3123,13 +3123,15 @@ var require_jsx_runtime = __commonJS({
3123
3123
  var index_exports = {};
3124
3124
  __export(index_exports, {
3125
3125
  AuthenticatorProvider: () => AuthenticatorProvider,
3126
- UserInfoCard: () => UserInfoCard
3126
+ EMPTY_GUID: () => EMPTY_GUID,
3127
+ LoginButton: () => LoginButton,
3128
+ SparkStudioAuthenticationSDK: () => SparkStudioAuthenticationSDK,
3129
+ UserInfoCard: () => UserInfoCard,
3130
+ UserProvider: () => UserProvider,
3131
+ useUser: () => useUser
3127
3132
  });
3128
3133
  module.exports = __toCommonJS(index_exports);
3129
3134
 
3130
- // src/components/UserInfoCard.tsx
3131
- var import_react3 = __toESM(require_react(), 1);
3132
-
3133
3135
  // src/context/UserProvider.tsx
3134
3136
  var import_react = __toESM(require_react(), 1);
3135
3137
 
@@ -3210,7 +3212,7 @@ var SparkStudioAuthenticationSDK = class {
3210
3212
  // src/context/UserProvider.tsx
3211
3213
  var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
3212
3214
  var UserContext = (0, import_react.createContext)(void 0);
3213
- var UserProvider = ({ children }) => {
3215
+ function UserProvider({ children }) {
3214
3216
  const [user, setUserState] = (0, import_react.useState)(null);
3215
3217
  (0, import_react.useEffect)(() => {
3216
3218
  const fetchUser = async () => {
@@ -3238,27 +3240,21 @@ var UserProvider = ({ children }) => {
3238
3240
  setUserState(null);
3239
3241
  };
3240
3242
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(UserContext.Provider, { value: { user, setUser, logout }, children });
3241
- };
3242
- var useUser = () => {
3243
+ }
3244
+ function useUser() {
3243
3245
  const context = (0, import_react.useContext)(UserContext);
3244
3246
  if (!context) throw new Error("useUser must be used inside UserProvider");
3245
3247
  return context;
3246
- };
3248
+ }
3247
3249
 
3248
3250
  // src/components/Buttons/LoginButton.tsx
3249
3251
  var import_react2 = __toESM(require_react(), 1);
3250
3252
  var import_google = require("@react-oauth/google");
3251
3253
  var import_common_ui = require("@sparkstudio/common-ui");
3252
-
3253
- // src/assets/icons/google_icon.webp
3254
- var google_icon_default = "./google_icon-IHKY4ITL.webp";
3255
-
3256
- // src/components/Buttons/LoginButton.tsx
3257
3254
  var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
3258
- var LoginButton = ({ onSuccess }) => {
3255
+ function LoginButton({ onSuccess }) {
3259
3256
  const { setUser } = useUser();
3260
- const resolveRef = (0, import_react2.useRef)(null);
3261
- const rejectRef = (0, import_react2.useRef)(null);
3257
+ const [loading, setLoading] = (0, import_react2.useState)(false);
3262
3258
  const login = (0, import_google.useGoogleLogin)({
3263
3259
  flow: "implicit",
3264
3260
  onSuccess: async (tokenResponse) => {
@@ -3269,62 +3265,54 @@ var LoginButton = ({ onSuccess }) => {
3269
3265
  });
3270
3266
  setUser(authentication?.User ?? null);
3271
3267
  onSuccess?.(tokenResponse);
3272
- resolveRef.current?.();
3273
3268
  } catch (error) {
3274
3269
  console.error("\u{1F534} Login failed (Google or backend SignIn)", error);
3275
- rejectRef.current?.(error);
3276
3270
  } finally {
3277
- resolveRef.current = null;
3278
- rejectRef.current = null;
3271
+ setLoading(false);
3279
3272
  }
3280
3273
  },
3281
3274
  onError: (error) => {
3282
3275
  console.error("\u274C Google Login Failed", error);
3283
- rejectRef.current?.(error);
3284
- resolveRef.current = null;
3285
- rejectRef.current = null;
3276
+ setLoading(false);
3286
3277
  }
3287
3278
  });
3288
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3289
- import_common_ui.Button,
3290
- {
3291
- loadingText: "Signing in...",
3292
- showSpinner: true,
3293
- onAction: () => new Promise((resolve, reject) => {
3294
- resolveRef.current = resolve;
3295
- rejectRef.current = reject;
3296
- login();
3297
- }),
3298
- renderContent: () => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
3299
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3300
- "img",
3301
- {
3302
- src: google_icon_default,
3303
- alt: "Google",
3304
- style: { width: "21px", height: "21px", margin: 0, padding: 0 }
3305
- }
3306
- ),
3307
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "d-none d-sm-inline ms-2", children: "Login" })
3308
- ] }),
3309
- renderLoading: () => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
3310
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3311
- "span",
3312
- {
3313
- className: "spinner-border spinner-border-sm me-2 async-btn__spinner",
3314
- role: "status",
3315
- "aria-hidden": "true"
3316
- }
3317
- ),
3318
- "Signing in..."
3319
- ] })
3279
+ const handleClick = () => {
3280
+ if (loading) return;
3281
+ setLoading(true);
3282
+ try {
3283
+ login();
3284
+ } catch (err) {
3285
+ console.error("Error starting Google login", err);
3286
+ setLoading(false);
3320
3287
  }
3321
- );
3322
- };
3288
+ };
3289
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_common_ui.Button, { onClick: handleClick, disabled: loading, children: loading ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
3290
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3291
+ "span",
3292
+ {
3293
+ className: "spinner-border spinner-border-sm me-2 async-btn__spinner",
3294
+ role: "status",
3295
+ "aria-hidden": "true"
3296
+ }
3297
+ ),
3298
+ "Signing in..."
3299
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
3300
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3301
+ "img",
3302
+ {
3303
+ src: "../../assets/icons/google_icon.webp",
3304
+ alt: "Google",
3305
+ style: { width: "21px", height: "21px", margin: 0, padding: 0 }
3306
+ }
3307
+ ),
3308
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "d-none d-sm-inline ms-2", children: "Login" })
3309
+ ] }) });
3310
+ }
3323
3311
 
3324
3312
  // src/components/UserInfoCard.tsx
3325
3313
  var import_common_ui2 = require("@sparkstudio/common-ui");
3326
3314
  var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
3327
- var UserInfoCard = () => {
3315
+ function UserInfoCard() {
3328
3316
  const { user, logout } = useUser();
3329
3317
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: user ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3330
3318
  import_common_ui2.Button,
@@ -3356,22 +3344,29 @@ var UserInfoCard = () => {
3356
3344
  ] })
3357
3345
  }
3358
3346
  ) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(LoginButton, {}) });
3359
- };
3347
+ }
3360
3348
 
3361
3349
  // src/components/AuthenticatorProvider.tsx
3362
- var import_react4 = __toESM(require_react(), 1);
3363
3350
  var import_google2 = require("@react-oauth/google");
3364
3351
  var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
3365
- var AuthenticatorProvider = ({
3352
+ function AuthenticatorProvider({
3366
3353
  googleClientId,
3367
3354
  children
3368
- }) => {
3355
+ }) {
3369
3356
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_google2.GoogleOAuthProvider, { clientId: googleClientId, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(UserProvider, { children }) });
3370
- };
3357
+ }
3358
+
3359
+ // src/types/Guid.ts
3360
+ var EMPTY_GUID = "00000000-0000-0000-0000-000000000000";
3371
3361
  // Annotate the CommonJS export names for ESM import in node:
3372
3362
  0 && (module.exports = {
3373
3363
  AuthenticatorProvider,
3374
- UserInfoCard
3364
+ EMPTY_GUID,
3365
+ LoginButton,
3366
+ SparkStudioAuthenticationSDK,
3367
+ UserInfoCard,
3368
+ UserProvider,
3369
+ useUser
3375
3370
  });
3376
3371
  /*! Bundled license information:
3377
3372