@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.d.cts CHANGED
@@ -1,15 +1,105 @@
1
- import React from 'react';
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
2
3
 
3
- declare const UserInfoCard: React.FC;
4
+ declare function UserInfoCard(): react_jsx_runtime.JSX.Element;
4
5
 
5
6
  interface AuthenticatorProviderProps {
6
7
  googleClientId: string;
7
- children: React.ReactNode;
8
+ children: ReactNode;
8
9
  }
9
10
  /**
10
11
  * Public entrypoint for consumers:
11
12
  * Wraps children with Google OAuth + User context.
12
13
  */
13
- declare const AuthenticatorProvider: React.FC<AuthenticatorProviderProps>;
14
+ declare function AuthenticatorProvider({ googleClientId, children, }: AuthenticatorProviderProps): react_jsx_runtime.JSX.Element;
14
15
 
15
- export { AuthenticatorProvider, type AuthenticatorProviderProps, UserInfoCard };
16
+ interface LoginButtonProps {
17
+ onSuccess?: (tokenResponse: any) => void;
18
+ }
19
+ declare function LoginButton({ onSuccess }: LoginButtonProps): react_jsx_runtime.JSX.Element;
20
+
21
+ /**
22
+ * Represents an Auto-generated model for UserDTO.
23
+ */
24
+ interface IUserDTO {
25
+ Sub?: string;
26
+ Name?: string;
27
+ Email?: string;
28
+ ProfilePicture?: string;
29
+ }
30
+ type UserDTOInit = Partial<IUserDTO>;
31
+ declare class UserDTO implements IUserDTO {
32
+ Sub?: string;
33
+ Name?: string;
34
+ Email?: string;
35
+ ProfilePicture?: string;
36
+ constructor(init: UserDTOInit);
37
+ }
38
+
39
+ interface UserContextType {
40
+ user: UserDTO | null;
41
+ setUser: (user: UserDTO | null) => void;
42
+ logout: () => Promise<void>;
43
+ }
44
+ interface UserProviderProps {
45
+ children: ReactNode;
46
+ }
47
+ declare function UserProvider({ children }: UserProviderProps): react_jsx_runtime.JSX.Element;
48
+ declare function useUser(): UserContextType;
49
+
50
+ type Guid = string;
51
+ declare const EMPTY_GUID: Guid;
52
+
53
+ /**
54
+ * Represents an Auto-generated model for TokenRequest.
55
+ */
56
+ interface ITokenRequest {
57
+ Token?: string;
58
+ }
59
+ type TokenRequestInit = Partial<ITokenRequest>;
60
+ declare class TokenRequest implements ITokenRequest {
61
+ Token?: string;
62
+ constructor(init: TokenRequestInit);
63
+ }
64
+
65
+ /**
66
+ * Represents an Auto-generated model for AuthResponse.
67
+ */
68
+ interface IAuthResponse {
69
+ User: UserDTO;
70
+ }
71
+ type AuthResponseInit = Partial<IAuthResponse> & Pick<IAuthResponse, "User">;
72
+ declare class AuthResponse implements IAuthResponse {
73
+ User: UserDTO;
74
+ constructor(init: AuthResponseInit);
75
+ }
76
+
77
+ /**
78
+ * Auto-generated client for the Auth controller.
79
+ */
80
+ declare class Auth {
81
+ private baseUrl;
82
+ constructor(baseUrl: string);
83
+ Logout(): Promise<UserDTO>;
84
+ GetCurrentUser(): Promise<UserDTO>;
85
+ SignIn(tokenRequest: TokenRequest): Promise<AuthResponse>;
86
+ }
87
+
88
+ /**
89
+ * Auto-generated client for the Home controller.
90
+ */
91
+ declare class Home {
92
+ private baseUrl;
93
+ constructor(baseUrl: string);
94
+ }
95
+
96
+ /**
97
+ * Auto-generated API client.
98
+ */
99
+ declare class SparkStudioAuthenticationSDK {
100
+ auth: Auth;
101
+ home: Home;
102
+ constructor(baseUrl: string);
103
+ }
104
+
105
+ export { AuthenticatorProvider, type AuthenticatorProviderProps, EMPTY_GUID, type Guid, LoginButton, SparkStudioAuthenticationSDK, UserInfoCard, UserProvider, useUser };
package/dist/index.d.ts CHANGED
@@ -1,15 +1,105 @@
1
- import React from 'react';
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
2
3
 
3
- declare const UserInfoCard: React.FC;
4
+ declare function UserInfoCard(): react_jsx_runtime.JSX.Element;
4
5
 
5
6
  interface AuthenticatorProviderProps {
6
7
  googleClientId: string;
7
- children: React.ReactNode;
8
+ children: ReactNode;
8
9
  }
9
10
  /**
10
11
  * Public entrypoint for consumers:
11
12
  * Wraps children with Google OAuth + User context.
12
13
  */
13
- declare const AuthenticatorProvider: React.FC<AuthenticatorProviderProps>;
14
+ declare function AuthenticatorProvider({ googleClientId, children, }: AuthenticatorProviderProps): react_jsx_runtime.JSX.Element;
14
15
 
15
- export { AuthenticatorProvider, type AuthenticatorProviderProps, UserInfoCard };
16
+ interface LoginButtonProps {
17
+ onSuccess?: (tokenResponse: any) => void;
18
+ }
19
+ declare function LoginButton({ onSuccess }: LoginButtonProps): react_jsx_runtime.JSX.Element;
20
+
21
+ /**
22
+ * Represents an Auto-generated model for UserDTO.
23
+ */
24
+ interface IUserDTO {
25
+ Sub?: string;
26
+ Name?: string;
27
+ Email?: string;
28
+ ProfilePicture?: string;
29
+ }
30
+ type UserDTOInit = Partial<IUserDTO>;
31
+ declare class UserDTO implements IUserDTO {
32
+ Sub?: string;
33
+ Name?: string;
34
+ Email?: string;
35
+ ProfilePicture?: string;
36
+ constructor(init: UserDTOInit);
37
+ }
38
+
39
+ interface UserContextType {
40
+ user: UserDTO | null;
41
+ setUser: (user: UserDTO | null) => void;
42
+ logout: () => Promise<void>;
43
+ }
44
+ interface UserProviderProps {
45
+ children: ReactNode;
46
+ }
47
+ declare function UserProvider({ children }: UserProviderProps): react_jsx_runtime.JSX.Element;
48
+ declare function useUser(): UserContextType;
49
+
50
+ type Guid = string;
51
+ declare const EMPTY_GUID: Guid;
52
+
53
+ /**
54
+ * Represents an Auto-generated model for TokenRequest.
55
+ */
56
+ interface ITokenRequest {
57
+ Token?: string;
58
+ }
59
+ type TokenRequestInit = Partial<ITokenRequest>;
60
+ declare class TokenRequest implements ITokenRequest {
61
+ Token?: string;
62
+ constructor(init: TokenRequestInit);
63
+ }
64
+
65
+ /**
66
+ * Represents an Auto-generated model for AuthResponse.
67
+ */
68
+ interface IAuthResponse {
69
+ User: UserDTO;
70
+ }
71
+ type AuthResponseInit = Partial<IAuthResponse> & Pick<IAuthResponse, "User">;
72
+ declare class AuthResponse implements IAuthResponse {
73
+ User: UserDTO;
74
+ constructor(init: AuthResponseInit);
75
+ }
76
+
77
+ /**
78
+ * Auto-generated client for the Auth controller.
79
+ */
80
+ declare class Auth {
81
+ private baseUrl;
82
+ constructor(baseUrl: string);
83
+ Logout(): Promise<UserDTO>;
84
+ GetCurrentUser(): Promise<UserDTO>;
85
+ SignIn(tokenRequest: TokenRequest): Promise<AuthResponse>;
86
+ }
87
+
88
+ /**
89
+ * Auto-generated client for the Home controller.
90
+ */
91
+ declare class Home {
92
+ private baseUrl;
93
+ constructor(baseUrl: string);
94
+ }
95
+
96
+ /**
97
+ * Auto-generated API client.
98
+ */
99
+ declare class SparkStudioAuthenticationSDK {
100
+ auth: Auth;
101
+ home: Home;
102
+ constructor(baseUrl: string);
103
+ }
104
+
105
+ export { AuthenticatorProvider, type AuthenticatorProviderProps, EMPTY_GUID, type Guid, LoginButton, SparkStudioAuthenticationSDK, UserInfoCard, UserProvider, useUser };
package/dist/index.js CHANGED
@@ -1356,7 +1356,7 @@ var require_react_development = __commonJS({
1356
1356
  }
1357
1357
  return dispatcher.useContext(Context);
1358
1358
  }
1359
- function useState2(initialState) {
1359
+ function useState3(initialState) {
1360
1360
  var dispatcher = resolveDispatcher();
1361
1361
  return dispatcher.useState(initialState);
1362
1362
  }
@@ -1364,7 +1364,7 @@ var require_react_development = __commonJS({
1364
1364
  var dispatcher = resolveDispatcher();
1365
1365
  return dispatcher.useReducer(reducer, initialArg, init);
1366
1366
  }
1367
- function useRef2(initialValue) {
1367
+ function useRef(initialValue) {
1368
1368
  var dispatcher = resolveDispatcher();
1369
1369
  return dispatcher.useRef(initialValue);
1370
1370
  }
@@ -2158,8 +2158,8 @@ var require_react_development = __commonJS({
2158
2158
  exports.useLayoutEffect = useLayoutEffect;
2159
2159
  exports.useMemo = useMemo;
2160
2160
  exports.useReducer = useReducer;
2161
- exports.useRef = useRef2;
2162
- exports.useState = useState2;
2161
+ exports.useRef = useRef;
2162
+ exports.useState = useState3;
2163
2163
  exports.useSyncExternalStore = useSyncExternalStore;
2164
2164
  exports.useTransition = useTransition;
2165
2165
  exports.version = ReactVersion;
@@ -2215,7 +2215,7 @@ var require_react_jsx_runtime_development = __commonJS({
2215
2215
  if (process.env.NODE_ENV !== "production") {
2216
2216
  (function() {
2217
2217
  "use strict";
2218
- var React5 = require_react();
2218
+ var React = require_react();
2219
2219
  var REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol.for("react.element");
2220
2220
  var REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for("react.portal");
2221
2221
  var REACT_FRAGMENT_TYPE = /* @__PURE__ */ Symbol.for("react.fragment");
@@ -2241,7 +2241,7 @@ var require_react_jsx_runtime_development = __commonJS({
2241
2241
  }
2242
2242
  return null;
2243
2243
  }
2244
- var ReactSharedInternals = React5.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2244
+ var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
2245
2245
  function error(format) {
2246
2246
  {
2247
2247
  {
@@ -3113,9 +3113,6 @@ var require_jsx_runtime = __commonJS({
3113
3113
  }
3114
3114
  });
3115
3115
 
3116
- // src/components/UserInfoCard.tsx
3117
- var import_react3 = __toESM(require_react(), 1);
3118
-
3119
3116
  // src/context/UserProvider.tsx
3120
3117
  var import_react = __toESM(require_react(), 1);
3121
3118
 
@@ -3196,7 +3193,7 @@ var SparkStudioAuthenticationSDK = class {
3196
3193
  // src/context/UserProvider.tsx
3197
3194
  var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
3198
3195
  var UserContext = (0, import_react.createContext)(void 0);
3199
- var UserProvider = ({ children }) => {
3196
+ function UserProvider({ children }) {
3200
3197
  const [user, setUserState] = (0, import_react.useState)(null);
3201
3198
  (0, import_react.useEffect)(() => {
3202
3199
  const fetchUser = async () => {
@@ -3224,27 +3221,21 @@ var UserProvider = ({ children }) => {
3224
3221
  setUserState(null);
3225
3222
  };
3226
3223
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(UserContext.Provider, { value: { user, setUser, logout }, children });
3227
- };
3228
- var useUser = () => {
3224
+ }
3225
+ function useUser() {
3229
3226
  const context = (0, import_react.useContext)(UserContext);
3230
3227
  if (!context) throw new Error("useUser must be used inside UserProvider");
3231
3228
  return context;
3232
- };
3229
+ }
3233
3230
 
3234
3231
  // src/components/Buttons/LoginButton.tsx
3235
3232
  var import_react2 = __toESM(require_react(), 1);
3236
3233
  import { useGoogleLogin } from "@react-oauth/google";
3237
- import { Button } from "@sparkstudio/common-ui";
3238
-
3239
- // src/assets/icons/google_icon.webp
3240
- var google_icon_default = "./google_icon-IHKY4ITL.webp";
3241
-
3242
- // src/components/Buttons/LoginButton.tsx
3243
3234
  var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
3244
- var LoginButton = ({ onSuccess }) => {
3235
+ import { Button } from "@sparkstudio/common-ui";
3236
+ function LoginButton({ onSuccess }) {
3245
3237
  const { setUser } = useUser();
3246
- const resolveRef = (0, import_react2.useRef)(null);
3247
- const rejectRef = (0, import_react2.useRef)(null);
3238
+ const [loading, setLoading] = (0, import_react2.useState)(false);
3248
3239
  const login = useGoogleLogin({
3249
3240
  flow: "implicit",
3250
3241
  onSuccess: async (tokenResponse) => {
@@ -3255,62 +3246,54 @@ var LoginButton = ({ onSuccess }) => {
3255
3246
  });
3256
3247
  setUser(authentication?.User ?? null);
3257
3248
  onSuccess?.(tokenResponse);
3258
- resolveRef.current?.();
3259
3249
  } catch (error) {
3260
3250
  console.error("\u{1F534} Login failed (Google or backend SignIn)", error);
3261
- rejectRef.current?.(error);
3262
3251
  } finally {
3263
- resolveRef.current = null;
3264
- rejectRef.current = null;
3252
+ setLoading(false);
3265
3253
  }
3266
3254
  },
3267
3255
  onError: (error) => {
3268
3256
  console.error("\u274C Google Login Failed", error);
3269
- rejectRef.current?.(error);
3270
- resolveRef.current = null;
3271
- rejectRef.current = null;
3257
+ setLoading(false);
3272
3258
  }
3273
3259
  });
3274
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3275
- Button,
3276
- {
3277
- loadingText: "Signing in...",
3278
- showSpinner: true,
3279
- onAction: () => new Promise((resolve, reject) => {
3280
- resolveRef.current = resolve;
3281
- rejectRef.current = reject;
3282
- login();
3283
- }),
3284
- renderContent: () => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
3285
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3286
- "img",
3287
- {
3288
- src: google_icon_default,
3289
- alt: "Google",
3290
- style: { width: "21px", height: "21px", margin: 0, padding: 0 }
3291
- }
3292
- ),
3293
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "d-none d-sm-inline ms-2", children: "Login" })
3294
- ] }),
3295
- renderLoading: () => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
3296
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3297
- "span",
3298
- {
3299
- className: "spinner-border spinner-border-sm me-2 async-btn__spinner",
3300
- role: "status",
3301
- "aria-hidden": "true"
3302
- }
3303
- ),
3304
- "Signing in..."
3305
- ] })
3260
+ const handleClick = () => {
3261
+ if (loading) return;
3262
+ setLoading(true);
3263
+ try {
3264
+ login();
3265
+ } catch (err) {
3266
+ console.error("Error starting Google login", err);
3267
+ setLoading(false);
3306
3268
  }
3307
- );
3308
- };
3269
+ };
3270
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Button, { onClick: handleClick, disabled: loading, children: loading ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
3271
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3272
+ "span",
3273
+ {
3274
+ className: "spinner-border spinner-border-sm me-2 async-btn__spinner",
3275
+ role: "status",
3276
+ "aria-hidden": "true"
3277
+ }
3278
+ ),
3279
+ "Signing in..."
3280
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
3281
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3282
+ "img",
3283
+ {
3284
+ src: "../../assets/icons/google_icon.webp",
3285
+ alt: "Google",
3286
+ style: { width: "21px", height: "21px", margin: 0, padding: 0 }
3287
+ }
3288
+ ),
3289
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "d-none d-sm-inline ms-2", children: "Login" })
3290
+ ] }) });
3291
+ }
3309
3292
 
3310
3293
  // src/components/UserInfoCard.tsx
3311
3294
  var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
3312
3295
  import { Button as Button2 } from "@sparkstudio/common-ui";
3313
- var UserInfoCard = () => {
3296
+ function UserInfoCard() {
3314
3297
  const { user, logout } = useUser();
3315
3298
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: user ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3316
3299
  Button2,
@@ -3342,21 +3325,28 @@ var UserInfoCard = () => {
3342
3325
  ] })
3343
3326
  }
3344
3327
  ) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(LoginButton, {}) });
3345
- };
3328
+ }
3346
3329
 
3347
3330
  // src/components/AuthenticatorProvider.tsx
3348
- var import_react4 = __toESM(require_react(), 1);
3349
3331
  import { GoogleOAuthProvider } from "@react-oauth/google";
3350
3332
  var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
3351
- var AuthenticatorProvider = ({
3333
+ function AuthenticatorProvider({
3352
3334
  googleClientId,
3353
3335
  children
3354
- }) => {
3336
+ }) {
3355
3337
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(GoogleOAuthProvider, { clientId: googleClientId, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(UserProvider, { children }) });
3356
- };
3338
+ }
3339
+
3340
+ // src/types/Guid.ts
3341
+ var EMPTY_GUID = "00000000-0000-0000-0000-000000000000";
3357
3342
  export {
3358
3343
  AuthenticatorProvider,
3359
- UserInfoCard
3344
+ EMPTY_GUID,
3345
+ LoginButton,
3346
+ SparkStudioAuthenticationSDK,
3347
+ UserInfoCard,
3348
+ UserProvider,
3349
+ useUser
3360
3350
  };
3361
3351
  /*! Bundled license information:
3362
3352