@sparkstudio/authentication-ui 1.0.14 → 1.0.16

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
@@ -104,7 +104,8 @@ var import_jsx_runtime = require("react/jsx-runtime");
104
104
  var UserContext = (0, import_react.createContext)(void 0);
105
105
  function UserProvider({
106
106
  children,
107
- apiUrl,
107
+ authenticationUrl,
108
+ accountsUrl,
108
109
  onLoginSuccess,
109
110
  onLoginFailed,
110
111
  onLogoutSuccess,
@@ -116,7 +117,7 @@ function UserProvider({
116
117
  const fetchUser = async () => {
117
118
  setIsLoading(true);
118
119
  try {
119
- const api = new SparkStudioAuthenticationSDK(apiUrl);
120
+ const api = new SparkStudioAuthenticationSDK(authenticationUrl);
120
121
  const me = await api.auth.GetCurrentUser();
121
122
  setUser(me);
122
123
  } catch (error) {
@@ -128,7 +129,7 @@ function UserProvider({
128
129
  }
129
130
  };
130
131
  fetchUser();
131
- }, [apiUrl]);
132
+ }, [authenticationUrl]);
132
133
  const setUser = (user2) => {
133
134
  setUserState(user2);
134
135
  if (user2) {
@@ -137,7 +138,7 @@ function UserProvider({
137
138
  };
138
139
  const logout = async () => {
139
140
  try {
140
- const api = new SparkStudioAuthenticationSDK(apiUrl);
141
+ const api = new SparkStudioAuthenticationSDK(authenticationUrl);
141
142
  await api.auth.Logout?.();
142
143
  onLogoutSuccess?.();
143
144
  } catch (err) {
@@ -156,7 +157,8 @@ function UserProvider({
156
157
  user,
157
158
  setUser,
158
159
  logout,
159
- apiUrl,
160
+ authenticationUrl,
161
+ accountsUrl,
160
162
  isAuthenticated: !!user,
161
163
  isLoading
162
164
  },
@@ -174,20 +176,23 @@ function useUser() {
174
176
  var import_react2 = require("react");
175
177
  var import_google = require("@react-oauth/google");
176
178
  var import_common_ui = require("@sparkstudio/common-ui");
179
+ var import_accounts_sdk = require("@sparkstudio/accounts-sdk");
177
180
  var import_jsx_runtime2 = require("react/jsx-runtime");
178
181
  function LoginButton({ onLogin, onLoginFailed }) {
179
- const { setUser, apiUrl } = useUser();
182
+ const { setUser, authenticationUrl, accountsUrl } = useUser();
180
183
  const [loading, setLoading] = (0, import_react2.useState)(false);
181
184
  const login = (0, import_google.useGoogleLogin)({
182
185
  flow: "implicit",
183
186
  onSuccess: async (tokenResponse) => {
184
187
  try {
185
- const api = new SparkStudioAuthenticationSDK(apiUrl);
188
+ const api = new SparkStudioAuthenticationSDK(authenticationUrl);
186
189
  const authentication = await api.auth.SignIn({
187
190
  Token: tokenResponse.access_token
188
191
  });
189
192
  const user = authentication?.User ?? null;
190
- setUser(user);
193
+ const accountsApi = new import_accounts_sdk.SparkStudioAccountsSDK(accountsUrl);
194
+ const dbUser = await accountsApi.users.SyncUser();
195
+ setUser(dbUser);
191
196
  onLogin?.(user);
192
197
  } catch (error) {
193
198
  console.error("\u{1F534} Login failed (Google or backend SignIn)", error);
@@ -297,7 +302,8 @@ var import_google2 = require("@react-oauth/google");
297
302
  var import_jsx_runtime4 = require("react/jsx-runtime");
298
303
  function AuthenticatorProvider({
299
304
  googleClientId,
300
- apiUrl,
305
+ authenticationUrl,
306
+ accountsUrl,
301
307
  children,
302
308
  onLoginSuccess,
303
309
  onLoginFailed,
@@ -307,7 +313,8 @@ function AuthenticatorProvider({
307
313
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_google2.GoogleOAuthProvider, { clientId: googleClientId, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
308
314
  UserProvider,
309
315
  {
310
- apiUrl,
316
+ authenticationUrl,
317
+ accountsUrl,
311
318
  onLoginSuccess,
312
319
  onLoginFailed,
313
320
  onLogoutSuccess,
package/dist/index.d.cts CHANGED
@@ -21,14 +21,15 @@ declare class UserDTO implements IUserDTO {
21
21
 
22
22
  interface UserInfoCardProps {
23
23
  onLogin?: (user: UserDTO) => void;
24
- onLoginFailed?: (error: string) => void;
24
+ onLoginFailed?: (error: unknown) => void;
25
25
  onLogout?: () => void;
26
26
  }
27
27
  declare function UserInfoCard({ onLogin, onLogout, onLoginFailed }: UserInfoCardProps): react_jsx_runtime.JSX.Element;
28
28
 
29
29
  interface AuthenticatorProviderProps {
30
30
  googleClientId: string;
31
- apiUrl: string;
31
+ authenticationUrl: string;
32
+ accountsUrl: string;
32
33
  children: ReactNode;
33
34
  onLoginSuccess?: (user: UserDTO | null) => void;
34
35
  onLoginFailed?: (error: unknown) => void;
@@ -39,7 +40,7 @@ interface AuthenticatorProviderProps {
39
40
  * Public entrypoint for consumers:
40
41
  * Wraps children with Google OAuth + User context.
41
42
  */
42
- declare function AuthenticatorProvider({ googleClientId, apiUrl, children, onLoginSuccess, onLoginFailed, onLogoutSuccess, onLogoutFailed, }: AuthenticatorProviderProps): react_jsx_runtime.JSX.Element;
43
+ declare function AuthenticatorProvider({ googleClientId, authenticationUrl, accountsUrl, children, onLoginSuccess, onLoginFailed, onLogoutSuccess, onLogoutFailed, }: AuthenticatorProviderProps): react_jsx_runtime.JSX.Element;
43
44
 
44
45
  /**
45
46
  * Represents an Auto-generated model for AuthResponse.
@@ -55,7 +56,7 @@ declare class AuthResponse implements IAuthResponse {
55
56
 
56
57
  interface LoginButtonProps {
57
58
  onLogin?: (user: AuthResponse["User"]) => void;
58
- onLoginFailed?: (error: any) => void;
59
+ onLoginFailed?: (error: unknown) => void;
59
60
  }
60
61
  declare function LoginButton({ onLogin, onLoginFailed }: LoginButtonProps): react_jsx_runtime.JSX.Element;
61
62
 
@@ -63,19 +64,21 @@ interface UserContextType {
63
64
  user: UserDTO | null;
64
65
  setUser: (user: UserDTO | null) => void;
65
66
  logout: () => Promise<void>;
66
- apiUrl: string;
67
+ authenticationUrl: string;
68
+ accountsUrl: string;
67
69
  isAuthenticated: boolean;
68
70
  isLoading: boolean;
69
71
  }
70
72
  interface UserProviderProps {
71
73
  children: ReactNode;
72
- apiUrl: string;
74
+ authenticationUrl: string;
75
+ accountsUrl: string;
73
76
  onLoginSuccess?: (user: UserDTO | null) => void;
74
77
  onLoginFailed?: (error: unknown) => void;
75
78
  onLogoutSuccess?: () => void;
76
79
  onLogoutFailed?: (error: unknown) => void;
77
80
  }
78
- declare function UserProvider({ children, apiUrl, onLoginSuccess, onLoginFailed, onLogoutSuccess, onLogoutFailed, }: UserProviderProps): react_jsx_runtime.JSX.Element;
81
+ declare function UserProvider({ children, authenticationUrl, accountsUrl, onLoginSuccess, onLoginFailed, onLogoutSuccess, onLogoutFailed, }: UserProviderProps): react_jsx_runtime.JSX.Element;
79
82
  declare function useUser(): UserContextType;
80
83
 
81
84
  type Guid = string;
package/dist/index.d.ts CHANGED
@@ -21,14 +21,15 @@ declare class UserDTO implements IUserDTO {
21
21
 
22
22
  interface UserInfoCardProps {
23
23
  onLogin?: (user: UserDTO) => void;
24
- onLoginFailed?: (error: string) => void;
24
+ onLoginFailed?: (error: unknown) => void;
25
25
  onLogout?: () => void;
26
26
  }
27
27
  declare function UserInfoCard({ onLogin, onLogout, onLoginFailed }: UserInfoCardProps): react_jsx_runtime.JSX.Element;
28
28
 
29
29
  interface AuthenticatorProviderProps {
30
30
  googleClientId: string;
31
- apiUrl: string;
31
+ authenticationUrl: string;
32
+ accountsUrl: string;
32
33
  children: ReactNode;
33
34
  onLoginSuccess?: (user: UserDTO | null) => void;
34
35
  onLoginFailed?: (error: unknown) => void;
@@ -39,7 +40,7 @@ interface AuthenticatorProviderProps {
39
40
  * Public entrypoint for consumers:
40
41
  * Wraps children with Google OAuth + User context.
41
42
  */
42
- declare function AuthenticatorProvider({ googleClientId, apiUrl, children, onLoginSuccess, onLoginFailed, onLogoutSuccess, onLogoutFailed, }: AuthenticatorProviderProps): react_jsx_runtime.JSX.Element;
43
+ declare function AuthenticatorProvider({ googleClientId, authenticationUrl, accountsUrl, children, onLoginSuccess, onLoginFailed, onLogoutSuccess, onLogoutFailed, }: AuthenticatorProviderProps): react_jsx_runtime.JSX.Element;
43
44
 
44
45
  /**
45
46
  * Represents an Auto-generated model for AuthResponse.
@@ -55,7 +56,7 @@ declare class AuthResponse implements IAuthResponse {
55
56
 
56
57
  interface LoginButtonProps {
57
58
  onLogin?: (user: AuthResponse["User"]) => void;
58
- onLoginFailed?: (error: any) => void;
59
+ onLoginFailed?: (error: unknown) => void;
59
60
  }
60
61
  declare function LoginButton({ onLogin, onLoginFailed }: LoginButtonProps): react_jsx_runtime.JSX.Element;
61
62
 
@@ -63,19 +64,21 @@ interface UserContextType {
63
64
  user: UserDTO | null;
64
65
  setUser: (user: UserDTO | null) => void;
65
66
  logout: () => Promise<void>;
66
- apiUrl: string;
67
+ authenticationUrl: string;
68
+ accountsUrl: string;
67
69
  isAuthenticated: boolean;
68
70
  isLoading: boolean;
69
71
  }
70
72
  interface UserProviderProps {
71
73
  children: ReactNode;
72
- apiUrl: string;
74
+ authenticationUrl: string;
75
+ accountsUrl: string;
73
76
  onLoginSuccess?: (user: UserDTO | null) => void;
74
77
  onLoginFailed?: (error: unknown) => void;
75
78
  onLogoutSuccess?: () => void;
76
79
  onLogoutFailed?: (error: unknown) => void;
77
80
  }
78
- declare function UserProvider({ children, apiUrl, onLoginSuccess, onLoginFailed, onLogoutSuccess, onLogoutFailed, }: UserProviderProps): react_jsx_runtime.JSX.Element;
81
+ declare function UserProvider({ children, authenticationUrl, accountsUrl, onLoginSuccess, onLoginFailed, onLogoutSuccess, onLogoutFailed, }: UserProviderProps): react_jsx_runtime.JSX.Element;
79
82
  declare function useUser(): UserContextType;
80
83
 
81
84
  type Guid = string;
package/dist/index.js CHANGED
@@ -77,7 +77,8 @@ import { jsx } from "react/jsx-runtime";
77
77
  var UserContext = createContext(void 0);
78
78
  function UserProvider({
79
79
  children,
80
- apiUrl,
80
+ authenticationUrl,
81
+ accountsUrl,
81
82
  onLoginSuccess,
82
83
  onLoginFailed,
83
84
  onLogoutSuccess,
@@ -89,7 +90,7 @@ function UserProvider({
89
90
  const fetchUser = async () => {
90
91
  setIsLoading(true);
91
92
  try {
92
- const api = new SparkStudioAuthenticationSDK(apiUrl);
93
+ const api = new SparkStudioAuthenticationSDK(authenticationUrl);
93
94
  const me = await api.auth.GetCurrentUser();
94
95
  setUser(me);
95
96
  } catch (error) {
@@ -101,7 +102,7 @@ function UserProvider({
101
102
  }
102
103
  };
103
104
  fetchUser();
104
- }, [apiUrl]);
105
+ }, [authenticationUrl]);
105
106
  const setUser = (user2) => {
106
107
  setUserState(user2);
107
108
  if (user2) {
@@ -110,7 +111,7 @@ function UserProvider({
110
111
  };
111
112
  const logout = async () => {
112
113
  try {
113
- const api = new SparkStudioAuthenticationSDK(apiUrl);
114
+ const api = new SparkStudioAuthenticationSDK(authenticationUrl);
114
115
  await api.auth.Logout?.();
115
116
  onLogoutSuccess?.();
116
117
  } catch (err) {
@@ -129,7 +130,8 @@ function UserProvider({
129
130
  user,
130
131
  setUser,
131
132
  logout,
132
- apiUrl,
133
+ authenticationUrl,
134
+ accountsUrl,
133
135
  isAuthenticated: !!user,
134
136
  isLoading
135
137
  },
@@ -147,20 +149,23 @@ function useUser() {
147
149
  import { useState as useState2 } from "react";
148
150
  import { useGoogleLogin } from "@react-oauth/google";
149
151
  import { Button } from "@sparkstudio/common-ui";
152
+ import { SparkStudioAccountsSDK } from "@sparkstudio/accounts-sdk";
150
153
  import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
151
154
  function LoginButton({ onLogin, onLoginFailed }) {
152
- const { setUser, apiUrl } = useUser();
155
+ const { setUser, authenticationUrl, accountsUrl } = useUser();
153
156
  const [loading, setLoading] = useState2(false);
154
157
  const login = useGoogleLogin({
155
158
  flow: "implicit",
156
159
  onSuccess: async (tokenResponse) => {
157
160
  try {
158
- const api = new SparkStudioAuthenticationSDK(apiUrl);
161
+ const api = new SparkStudioAuthenticationSDK(authenticationUrl);
159
162
  const authentication = await api.auth.SignIn({
160
163
  Token: tokenResponse.access_token
161
164
  });
162
165
  const user = authentication?.User ?? null;
163
- setUser(user);
166
+ const accountsApi = new SparkStudioAccountsSDK(accountsUrl);
167
+ const dbUser = await accountsApi.users.SyncUser();
168
+ setUser(dbUser);
164
169
  onLogin?.(user);
165
170
  } catch (error) {
166
171
  console.error("\u{1F534} Login failed (Google or backend SignIn)", error);
@@ -270,7 +275,8 @@ import { GoogleOAuthProvider } from "@react-oauth/google";
270
275
  import { jsx as jsx4 } from "react/jsx-runtime";
271
276
  function AuthenticatorProvider({
272
277
  googleClientId,
273
- apiUrl,
278
+ authenticationUrl,
279
+ accountsUrl,
274
280
  children,
275
281
  onLoginSuccess,
276
282
  onLoginFailed,
@@ -280,7 +286,8 @@ function AuthenticatorProvider({
280
286
  return /* @__PURE__ */ jsx4(GoogleOAuthProvider, { clientId: googleClientId, children: /* @__PURE__ */ jsx4(
281
287
  UserProvider,
282
288
  {
283
- apiUrl,
289
+ authenticationUrl,
290
+ accountsUrl,
284
291
  onLoginSuccess,
285
292
  onLoginFailed,
286
293
  onLogoutSuccess,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkstudio/authentication-ui",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -35,6 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@react-oauth/google": "^0.13.4",
38
+ "@sparkstudio/accounts-sdk": "^1.1.64",
38
39
  "@sparkstudio/accounts-ui": "^1.1.56",
39
40
  "@sparkstudio/common-ui": "^1.0.5",
40
41
  "rimraf": "^6.1.2"