@sparkstudio/authentication-ui 1.0.3 → 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 +50 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -9
- package/dist/index.d.ts +11 -9
- package/dist/index.js +50 -63
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
2
3
|
|
|
3
|
-
declare
|
|
4
|
+
declare function UserInfoCard(): react_jsx_runtime.JSX.Element;
|
|
4
5
|
|
|
5
6
|
interface AuthenticatorProviderProps {
|
|
6
7
|
googleClientId: string;
|
|
7
|
-
children:
|
|
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
|
|
14
|
+
declare function AuthenticatorProvider({ googleClientId, children, }: AuthenticatorProviderProps): react_jsx_runtime.JSX.Element;
|
|
14
15
|
|
|
15
16
|
interface LoginButtonProps {
|
|
16
17
|
onSuccess?: (tokenResponse: any) => void;
|
|
17
18
|
}
|
|
18
|
-
declare
|
|
19
|
+
declare function LoginButton({ onSuccess }: LoginButtonProps): react_jsx_runtime.JSX.Element;
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Represents an Auto-generated model for UserDTO.
|
|
@@ -40,10 +41,11 @@ interface UserContextType {
|
|
|
40
41
|
setUser: (user: UserDTO | null) => void;
|
|
41
42
|
logout: () => Promise<void>;
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
children:
|
|
45
|
-
}
|
|
46
|
-
declare
|
|
44
|
+
interface UserProviderProps {
|
|
45
|
+
children: ReactNode;
|
|
46
|
+
}
|
|
47
|
+
declare function UserProvider({ children }: UserProviderProps): react_jsx_runtime.JSX.Element;
|
|
48
|
+
declare function useUser(): UserContextType;
|
|
47
49
|
|
|
48
50
|
type Guid = string;
|
|
49
51
|
declare const EMPTY_GUID: Guid;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
2
3
|
|
|
3
|
-
declare
|
|
4
|
+
declare function UserInfoCard(): react_jsx_runtime.JSX.Element;
|
|
4
5
|
|
|
5
6
|
interface AuthenticatorProviderProps {
|
|
6
7
|
googleClientId: string;
|
|
7
|
-
children:
|
|
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
|
|
14
|
+
declare function AuthenticatorProvider({ googleClientId, children, }: AuthenticatorProviderProps): react_jsx_runtime.JSX.Element;
|
|
14
15
|
|
|
15
16
|
interface LoginButtonProps {
|
|
16
17
|
onSuccess?: (tokenResponse: any) => void;
|
|
17
18
|
}
|
|
18
|
-
declare
|
|
19
|
+
declare function LoginButton({ onSuccess }: LoginButtonProps): react_jsx_runtime.JSX.Element;
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Represents an Auto-generated model for UserDTO.
|
|
@@ -40,10 +41,11 @@ interface UserContextType {
|
|
|
40
41
|
setUser: (user: UserDTO | null) => void;
|
|
41
42
|
logout: () => Promise<void>;
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
children:
|
|
45
|
-
}
|
|
46
|
-
declare
|
|
44
|
+
interface UserProviderProps {
|
|
45
|
+
children: ReactNode;
|
|
46
|
+
}
|
|
47
|
+
declare function UserProvider({ children }: UserProviderProps): react_jsx_runtime.JSX.Element;
|
|
48
|
+
declare function useUser(): UserContextType;
|
|
47
49
|
|
|
48
50
|
type Guid = string;
|
|
49
51
|
declare const EMPTY_GUID: Guid;
|
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
|
|
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
|
|
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 =
|
|
2162
|
-
exports.useState =
|
|
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
|
|
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 =
|
|
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
|
-
|
|
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,22 +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
|
-
|
|
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
3234
|
var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
|
|
3238
3235
|
import { Button } from "@sparkstudio/common-ui";
|
|
3239
|
-
|
|
3236
|
+
function LoginButton({ onSuccess }) {
|
|
3240
3237
|
const { setUser } = useUser();
|
|
3241
|
-
const
|
|
3242
|
-
const rejectRef = (0, import_react2.useRef)(null);
|
|
3238
|
+
const [loading, setLoading] = (0, import_react2.useState)(false);
|
|
3243
3239
|
const login = useGoogleLogin({
|
|
3244
3240
|
flow: "implicit",
|
|
3245
3241
|
onSuccess: async (tokenResponse) => {
|
|
@@ -3250,62 +3246,54 @@ var LoginButton = ({ onSuccess }) => {
|
|
|
3250
3246
|
});
|
|
3251
3247
|
setUser(authentication?.User ?? null);
|
|
3252
3248
|
onSuccess?.(tokenResponse);
|
|
3253
|
-
resolveRef.current?.();
|
|
3254
3249
|
} catch (error) {
|
|
3255
3250
|
console.error("\u{1F534} Login failed (Google or backend SignIn)", error);
|
|
3256
|
-
rejectRef.current?.(error);
|
|
3257
3251
|
} finally {
|
|
3258
|
-
|
|
3259
|
-
rejectRef.current = null;
|
|
3252
|
+
setLoading(false);
|
|
3260
3253
|
}
|
|
3261
3254
|
},
|
|
3262
3255
|
onError: (error) => {
|
|
3263
3256
|
console.error("\u274C Google Login Failed", error);
|
|
3264
|
-
|
|
3265
|
-
resolveRef.current = null;
|
|
3266
|
-
rejectRef.current = null;
|
|
3257
|
+
setLoading(false);
|
|
3267
3258
|
}
|
|
3268
3259
|
});
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
login();
|
|
3278
|
-
}),
|
|
3279
|
-
renderContent: () => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
3280
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
3281
|
-
"img",
|
|
3282
|
-
{
|
|
3283
|
-
src: "../../assets/icons/google_icon.webp",
|
|
3284
|
-
alt: "Google",
|
|
3285
|
-
style: { width: "21px", height: "21px", margin: 0, padding: 0 }
|
|
3286
|
-
}
|
|
3287
|
-
),
|
|
3288
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "d-none d-sm-inline ms-2", children: "Login" })
|
|
3289
|
-
] }),
|
|
3290
|
-
renderLoading: () => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
3291
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
3292
|
-
"span",
|
|
3293
|
-
{
|
|
3294
|
-
className: "spinner-border spinner-border-sm me-2 async-btn__spinner",
|
|
3295
|
-
role: "status",
|
|
3296
|
-
"aria-hidden": "true"
|
|
3297
|
-
}
|
|
3298
|
-
),
|
|
3299
|
-
"Signing in..."
|
|
3300
|
-
] })
|
|
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);
|
|
3301
3268
|
}
|
|
3302
|
-
|
|
3303
|
-
|
|
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
|
+
}
|
|
3304
3292
|
|
|
3305
3293
|
// src/components/UserInfoCard.tsx
|
|
3306
3294
|
var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
|
|
3307
3295
|
import { Button as Button2 } from "@sparkstudio/common-ui";
|
|
3308
|
-
|
|
3296
|
+
function UserInfoCard() {
|
|
3309
3297
|
const { user, logout } = useUser();
|
|
3310
3298
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: user ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
3311
3299
|
Button2,
|
|
@@ -3337,18 +3325,17 @@ var UserInfoCard = () => {
|
|
|
3337
3325
|
] })
|
|
3338
3326
|
}
|
|
3339
3327
|
) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(LoginButton, {}) });
|
|
3340
|
-
}
|
|
3328
|
+
}
|
|
3341
3329
|
|
|
3342
3330
|
// src/components/AuthenticatorProvider.tsx
|
|
3343
|
-
var import_react4 = __toESM(require_react(), 1);
|
|
3344
3331
|
import { GoogleOAuthProvider } from "@react-oauth/google";
|
|
3345
3332
|
var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
|
|
3346
|
-
|
|
3333
|
+
function AuthenticatorProvider({
|
|
3347
3334
|
googleClientId,
|
|
3348
3335
|
children
|
|
3349
|
-
})
|
|
3336
|
+
}) {
|
|
3350
3337
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(GoogleOAuthProvider, { clientId: googleClientId, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(UserProvider, { children }) });
|
|
3351
|
-
}
|
|
3338
|
+
}
|
|
3352
3339
|
|
|
3353
3340
|
// src/types/Guid.ts
|
|
3354
3341
|
var EMPTY_GUID = "00000000-0000-0000-0000-000000000000";
|