@pixygon/auth 1.0.0 → 1.1.0
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/README.md +1 -1
- package/dist/{chunk-E34M2RJD.mjs → chunk-ELVIBXBG.mjs} +61 -4
- package/dist/components/index.d.mts +5 -5
- package/dist/components/index.d.ts +5 -5
- package/dist/components/index.js +115 -86
- package/dist/components/index.mjs +100 -83
- package/dist/{index-CIK2MKl9.d.mts → index-CuhQGwDH.d.mts} +32 -3
- package/dist/{index-CIK2MKl9.d.ts → index-CuhQGwDH.d.ts} +32 -3
- package/dist/index.d.mts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +62 -4
- package/dist/index.mjs +3 -1
- package/package.json +1 -1
- package/src/api/client.ts +34 -1
- package/src/components/ForgotPasswordForm.tsx +26 -23
- package/src/components/LoginForm.tsx +18 -15
- package/src/components/PixygonAuth.tsx +11 -0
- package/src/components/RegisterForm.tsx +21 -18
- package/src/components/VerifyForm.tsx +19 -16
- package/src/hooks/index.ts +2 -0
- package/src/index.ts +9 -0
- package/src/providers/AuthProvider.tsx +12 -0
- package/src/types/index.ts +51 -2
- package/src/utils/storage.ts +15 -3
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ function App() {
|
|
|
32
32
|
return (
|
|
33
33
|
<AuthProvider
|
|
34
34
|
config={{
|
|
35
|
-
baseUrl: 'https://pixygon
|
|
35
|
+
baseUrl: 'https://api.pixygon.com/v1',
|
|
36
36
|
appId: 'pixygon-ai', // Unique ID for token storage
|
|
37
37
|
appName: 'Pixygon AI',
|
|
38
38
|
debug: process.env.NODE_ENV === 'development',
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
// src/types/index.ts
|
|
2
|
+
var DEFAULT_THEME = {
|
|
3
|
+
primaryColor: "#6366f1",
|
|
4
|
+
backgroundColor: "#0f0f0f",
|
|
5
|
+
surfaceColor: "#262626",
|
|
6
|
+
textColor: "#ffffff",
|
|
7
|
+
textSecondary: "#a3a3a3",
|
|
8
|
+
errorColor: "#ef4444",
|
|
9
|
+
successColor: "#22c55e",
|
|
10
|
+
borderRadius: "1rem",
|
|
11
|
+
fontFamily: "inherit"
|
|
12
|
+
};
|
|
13
|
+
|
|
1
14
|
// src/utils/storage.ts
|
|
2
15
|
var getKeys = (appId) => ({
|
|
3
16
|
ACCESS_TOKEN: `${appId}_access_token`,
|
|
@@ -8,15 +21,25 @@ var getKeys = (appId) => ({
|
|
|
8
21
|
var defaultStorage = {
|
|
9
22
|
getItem: (key) => {
|
|
10
23
|
if (typeof window === "undefined") return null;
|
|
11
|
-
|
|
24
|
+
try {
|
|
25
|
+
return localStorage.getItem(key);
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
12
29
|
},
|
|
13
30
|
setItem: (key, value) => {
|
|
14
31
|
if (typeof window === "undefined") return;
|
|
15
|
-
|
|
32
|
+
try {
|
|
33
|
+
localStorage.setItem(key, value);
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
16
36
|
},
|
|
17
37
|
removeItem: (key) => {
|
|
18
38
|
if (typeof window === "undefined") return;
|
|
19
|
-
|
|
39
|
+
try {
|
|
40
|
+
localStorage.removeItem(key);
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
20
43
|
}
|
|
21
44
|
};
|
|
22
45
|
function createTokenStorage(appId, storage = defaultStorage) {
|
|
@@ -276,6 +299,9 @@ function createAuthApiClient(config, tokenStorage) {
|
|
|
276
299
|
method: "POST",
|
|
277
300
|
body: JSON.stringify(data)
|
|
278
301
|
});
|
|
302
|
+
if (!response.user || !response.token) {
|
|
303
|
+
throw createAuthError(401, response.message || "Login failed");
|
|
304
|
+
}
|
|
279
305
|
currentAccessToken = response.token;
|
|
280
306
|
await tokenStorage.setTokens(
|
|
281
307
|
response.token,
|
|
@@ -284,7 +310,7 @@ function createAuthApiClient(config, tokenStorage) {
|
|
|
284
310
|
response.user
|
|
285
311
|
);
|
|
286
312
|
config.onLogin?.(response.user);
|
|
287
|
-
log("Login successful:", response.user
|
|
313
|
+
log("Login successful:", response.user?.userName);
|
|
288
314
|
return response;
|
|
289
315
|
},
|
|
290
316
|
async register(data) {
|
|
@@ -349,6 +375,26 @@ function createAuthApiClient(config, tokenStorage) {
|
|
|
349
375
|
});
|
|
350
376
|
return response;
|
|
351
377
|
},
|
|
378
|
+
async changePassword(data) {
|
|
379
|
+
const response = await request("/auth/changePassword", {
|
|
380
|
+
method: "POST",
|
|
381
|
+
body: JSON.stringify(data)
|
|
382
|
+
});
|
|
383
|
+
log("Password changed successfully");
|
|
384
|
+
return response;
|
|
385
|
+
},
|
|
386
|
+
async logout() {
|
|
387
|
+
try {
|
|
388
|
+
const response = await request("/auth/logout", {
|
|
389
|
+
method: "POST"
|
|
390
|
+
});
|
|
391
|
+
log("Logout successful");
|
|
392
|
+
return response;
|
|
393
|
+
} catch (error) {
|
|
394
|
+
log("Logout request failed, continuing with local cleanup:", error);
|
|
395
|
+
return { status: "ok" };
|
|
396
|
+
}
|
|
397
|
+
},
|
|
352
398
|
// ========================================================================
|
|
353
399
|
// User Endpoints
|
|
354
400
|
// ========================================================================
|
|
@@ -647,8 +693,15 @@ function AuthProvider({ config: userConfig, children }) {
|
|
|
647
693
|
},
|
|
648
694
|
[apiClient]
|
|
649
695
|
);
|
|
696
|
+
const changePassword = useCallback(
|
|
697
|
+
async (data) => {
|
|
698
|
+
return apiClient.changePassword(data);
|
|
699
|
+
},
|
|
700
|
+
[apiClient]
|
|
701
|
+
);
|
|
650
702
|
const logout = useCallback(async () => {
|
|
651
703
|
log("Logging out...");
|
|
704
|
+
await apiClient.logout();
|
|
652
705
|
await tokenStorage.clear();
|
|
653
706
|
apiClient.setAccessToken(null);
|
|
654
707
|
setState({
|
|
@@ -697,6 +750,7 @@ function AuthProvider({ config: userConfig, children }) {
|
|
|
697
750
|
resendVerification,
|
|
698
751
|
forgotPassword,
|
|
699
752
|
recoverPassword,
|
|
753
|
+
changePassword,
|
|
700
754
|
refreshTokens,
|
|
701
755
|
// Utilities
|
|
702
756
|
getAccessToken,
|
|
@@ -713,6 +767,7 @@ function AuthProvider({ config: userConfig, children }) {
|
|
|
713
767
|
resendVerification,
|
|
714
768
|
forgotPassword,
|
|
715
769
|
recoverPassword,
|
|
770
|
+
changePassword,
|
|
716
771
|
refreshTokens,
|
|
717
772
|
getAccessToken,
|
|
718
773
|
hasRole,
|
|
@@ -889,6 +944,7 @@ function useAuth() {
|
|
|
889
944
|
resendVerification: context.resendVerification,
|
|
890
945
|
forgotPassword: context.forgotPassword,
|
|
891
946
|
recoverPassword: context.recoverPassword,
|
|
947
|
+
changePassword: context.changePassword,
|
|
892
948
|
// Utilities
|
|
893
949
|
hasRole: context.hasRole
|
|
894
950
|
}),
|
|
@@ -988,6 +1044,7 @@ function useAuthError() {
|
|
|
988
1044
|
}
|
|
989
1045
|
|
|
990
1046
|
export {
|
|
1047
|
+
DEFAULT_THEME,
|
|
991
1048
|
createTokenStorage,
|
|
992
1049
|
createAuthApiClient,
|
|
993
1050
|
AuthContext,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { P as PixygonAuthProps,
|
|
2
|
+
import { P as PixygonAuthProps, v as LoginFormProps, w as RegisterFormProps, y as VerifyFormProps, u as ForgotPasswordFormProps } from '../index-CuhQGwDH.mjs';
|
|
3
3
|
|
|
4
4
|
declare function PixygonAuth({ mode: initialMode, onSuccess, onError, onModeChange, userName: initialUserName, showBranding, theme, className, }: PixygonAuthProps): react_jsx_runtime.JSX.Element;
|
|
5
5
|
|
|
6
|
-
declare function LoginForm({ onSuccess, onError, onNavigateRegister, onNavigateForgotPassword, showBranding, className, }: LoginFormProps): react_jsx_runtime.JSX.Element;
|
|
6
|
+
declare function LoginForm({ onSuccess, onError, onNavigateRegister, onNavigateForgotPassword, showBranding, className, theme, }: LoginFormProps): react_jsx_runtime.JSX.Element;
|
|
7
7
|
|
|
8
|
-
declare function RegisterForm({ onSuccess, onError, onNavigateLogin, showBranding, className, }: RegisterFormProps): react_jsx_runtime.JSX.Element;
|
|
8
|
+
declare function RegisterForm({ onSuccess, onError, onNavigateLogin, showBranding, className, theme, }: RegisterFormProps): react_jsx_runtime.JSX.Element;
|
|
9
9
|
|
|
10
|
-
declare function VerifyForm({ userName, onSuccess, onError, onNavigateLogin, showBranding, className, }: VerifyFormProps): react_jsx_runtime.JSX.Element;
|
|
10
|
+
declare function VerifyForm({ userName, onSuccess, onError, onNavigateLogin, showBranding, className, theme, }: VerifyFormProps): react_jsx_runtime.JSX.Element;
|
|
11
11
|
|
|
12
|
-
declare function ForgotPasswordForm({ onSuccess, onError, onNavigateLogin, showBranding, className, }: ForgotPasswordFormProps): react_jsx_runtime.JSX.Element;
|
|
12
|
+
declare function ForgotPasswordForm({ onSuccess, onError, onNavigateLogin, showBranding, className, theme, }: ForgotPasswordFormProps): react_jsx_runtime.JSX.Element;
|
|
13
13
|
|
|
14
14
|
export { ForgotPasswordForm, ForgotPasswordFormProps, LoginForm, LoginFormProps, PixygonAuth, PixygonAuthProps, RegisterForm, RegisterFormProps, VerifyForm, VerifyFormProps };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { P as PixygonAuthProps,
|
|
2
|
+
import { P as PixygonAuthProps, v as LoginFormProps, w as RegisterFormProps, y as VerifyFormProps, u as ForgotPasswordFormProps } from '../index-CuhQGwDH.js';
|
|
3
3
|
|
|
4
4
|
declare function PixygonAuth({ mode: initialMode, onSuccess, onError, onModeChange, userName: initialUserName, showBranding, theme, className, }: PixygonAuthProps): react_jsx_runtime.JSX.Element;
|
|
5
5
|
|
|
6
|
-
declare function LoginForm({ onSuccess, onError, onNavigateRegister, onNavigateForgotPassword, showBranding, className, }: LoginFormProps): react_jsx_runtime.JSX.Element;
|
|
6
|
+
declare function LoginForm({ onSuccess, onError, onNavigateRegister, onNavigateForgotPassword, showBranding, className, theme, }: LoginFormProps): react_jsx_runtime.JSX.Element;
|
|
7
7
|
|
|
8
|
-
declare function RegisterForm({ onSuccess, onError, onNavigateLogin, showBranding, className, }: RegisterFormProps): react_jsx_runtime.JSX.Element;
|
|
8
|
+
declare function RegisterForm({ onSuccess, onError, onNavigateLogin, showBranding, className, theme, }: RegisterFormProps): react_jsx_runtime.JSX.Element;
|
|
9
9
|
|
|
10
|
-
declare function VerifyForm({ userName, onSuccess, onError, onNavigateLogin, showBranding, className, }: VerifyFormProps): react_jsx_runtime.JSX.Element;
|
|
10
|
+
declare function VerifyForm({ userName, onSuccess, onError, onNavigateLogin, showBranding, className, theme, }: VerifyFormProps): react_jsx_runtime.JSX.Element;
|
|
11
11
|
|
|
12
|
-
declare function ForgotPasswordForm({ onSuccess, onError, onNavigateLogin, showBranding, className, }: ForgotPasswordFormProps): react_jsx_runtime.JSX.Element;
|
|
12
|
+
declare function ForgotPasswordForm({ onSuccess, onError, onNavigateLogin, showBranding, className, theme, }: ForgotPasswordFormProps): react_jsx_runtime.JSX.Element;
|
|
13
13
|
|
|
14
14
|
export { ForgotPasswordForm, ForgotPasswordFormProps, LoginForm, LoginFormProps, PixygonAuth, PixygonAuthProps, RegisterForm, RegisterFormProps, VerifyForm, VerifyFormProps };
|