@pixygon/auth 1.0.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 +267 -0
- package/dist/chunk-E34M2RJD.mjs +1003 -0
- package/dist/components/index.d.mts +14 -0
- package/dist/components/index.d.ts +14 -0
- package/dist/components/index.js +1720 -0
- package/dist/components/index.mjs +1646 -0
- package/dist/index-CIK2MKl9.d.mts +201 -0
- package/dist/index-CIK2MKl9.d.ts +201 -0
- package/dist/index.d.mts +233 -0
- package/dist/index.d.ts +233 -0
- package/dist/index.js +1037 -0
- package/dist/index.mjs +28 -0
- package/package.json +58 -0
- package/src/api/client.ts +358 -0
- package/src/components/ForgotPasswordForm.tsx +410 -0
- package/src/components/LoginForm.tsx +323 -0
- package/src/components/PixygonAuth.tsx +170 -0
- package/src/components/RegisterForm.tsx +463 -0
- package/src/components/VerifyForm.tsx +411 -0
- package/src/components/index.ts +40 -0
- package/src/components/styles.ts +282 -0
- package/src/hooks/index.ts +284 -0
- package/src/hooks/useProfileSync.ts +201 -0
- package/src/index.ts +99 -0
- package/src/providers/AuthProvider.tsx +480 -0
- package/src/types/index.ts +310 -0
- package/src/utils/storage.ts +167 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pixygon/auth - Shared Types
|
|
3
|
+
* Type definitions for the Pixygon authentication system
|
|
4
|
+
*/
|
|
5
|
+
type UserRole = 'user' | 'creator' | 'admin' | 'superadmin';
|
|
6
|
+
type SubscriptionTier = 'free' | 'basic' | 'pro' | 'family' | 'enterprise';
|
|
7
|
+
interface User {
|
|
8
|
+
_id: string;
|
|
9
|
+
userName: string;
|
|
10
|
+
email: string;
|
|
11
|
+
isVerified: boolean;
|
|
12
|
+
role: UserRole;
|
|
13
|
+
firstName?: string;
|
|
14
|
+
lastName?: string;
|
|
15
|
+
profilePicture?: string;
|
|
16
|
+
subscriptionTier?: SubscriptionTier;
|
|
17
|
+
stripeCustomerId?: string;
|
|
18
|
+
dailyTokens?: number;
|
|
19
|
+
purchasedTokens?: number;
|
|
20
|
+
bonusTokens?: number;
|
|
21
|
+
subscriptionTokens?: number;
|
|
22
|
+
isChildAccount?: boolean;
|
|
23
|
+
parentUserId?: string;
|
|
24
|
+
apiAccess?: boolean;
|
|
25
|
+
discordUserId?: string;
|
|
26
|
+
twitchUser?: string;
|
|
27
|
+
createdAt?: string;
|
|
28
|
+
updatedAt?: string;
|
|
29
|
+
}
|
|
30
|
+
interface TokenPair {
|
|
31
|
+
accessToken: string;
|
|
32
|
+
refreshToken: string;
|
|
33
|
+
expiresIn: number;
|
|
34
|
+
refreshExpiresIn: number;
|
|
35
|
+
}
|
|
36
|
+
interface TokenPayload {
|
|
37
|
+
id: string;
|
|
38
|
+
role?: UserRole;
|
|
39
|
+
iat: number;
|
|
40
|
+
exp: number;
|
|
41
|
+
}
|
|
42
|
+
type AuthStatus = 'idle' | 'loading' | 'authenticated' | 'unauthenticated' | 'verifying';
|
|
43
|
+
interface AuthState {
|
|
44
|
+
user: User | null;
|
|
45
|
+
accessToken: string | null;
|
|
46
|
+
refreshToken: string | null;
|
|
47
|
+
status: AuthStatus;
|
|
48
|
+
isLoading: boolean;
|
|
49
|
+
error: AuthError | null;
|
|
50
|
+
}
|
|
51
|
+
interface LoginRequest {
|
|
52
|
+
userName: string;
|
|
53
|
+
password: string;
|
|
54
|
+
}
|
|
55
|
+
interface LoginResponse {
|
|
56
|
+
user: User;
|
|
57
|
+
token: string;
|
|
58
|
+
refreshToken?: string;
|
|
59
|
+
expiresIn?: number;
|
|
60
|
+
message?: string;
|
|
61
|
+
}
|
|
62
|
+
interface RegisterRequest {
|
|
63
|
+
userName: string;
|
|
64
|
+
email: string;
|
|
65
|
+
password: string;
|
|
66
|
+
confirmPassword?: string;
|
|
67
|
+
}
|
|
68
|
+
interface RegisterResponse {
|
|
69
|
+
user: User;
|
|
70
|
+
message?: string;
|
|
71
|
+
}
|
|
72
|
+
interface VerifyRequest {
|
|
73
|
+
userName: string;
|
|
74
|
+
verificationCode: string;
|
|
75
|
+
}
|
|
76
|
+
interface VerifyResponse {
|
|
77
|
+
user: User;
|
|
78
|
+
token: string;
|
|
79
|
+
refreshToken?: string;
|
|
80
|
+
message?: string;
|
|
81
|
+
}
|
|
82
|
+
interface ForgotPasswordRequest {
|
|
83
|
+
email: string;
|
|
84
|
+
}
|
|
85
|
+
interface ForgotPasswordResponse {
|
|
86
|
+
message: string;
|
|
87
|
+
}
|
|
88
|
+
interface RecoverPasswordRequest {
|
|
89
|
+
email: string;
|
|
90
|
+
recoveryCode: string;
|
|
91
|
+
newPassword: string;
|
|
92
|
+
}
|
|
93
|
+
interface RecoverPasswordResponse {
|
|
94
|
+
message: string;
|
|
95
|
+
}
|
|
96
|
+
interface RefreshTokenRequest {
|
|
97
|
+
refreshToken: string;
|
|
98
|
+
}
|
|
99
|
+
interface RefreshTokenResponse {
|
|
100
|
+
token: string;
|
|
101
|
+
refreshToken: string;
|
|
102
|
+
expiresIn: number;
|
|
103
|
+
}
|
|
104
|
+
interface ResendVerificationRequest {
|
|
105
|
+
userName: string;
|
|
106
|
+
}
|
|
107
|
+
interface ResendVerificationResponse {
|
|
108
|
+
message: string;
|
|
109
|
+
}
|
|
110
|
+
type AuthErrorCode = 'INVALID_CREDENTIALS' | 'USER_NOT_FOUND' | 'USER_EXISTS' | 'EMAIL_NOT_VERIFIED' | 'INVALID_VERIFICATION_CODE' | 'EXPIRED_VERIFICATION_CODE' | 'INVALID_RECOVERY_CODE' | 'EXPIRED_RECOVERY_CODE' | 'TOKEN_EXPIRED' | 'TOKEN_INVALID' | 'REFRESH_TOKEN_EXPIRED' | 'NETWORK_ERROR' | 'SERVER_ERROR' | 'UNKNOWN_ERROR';
|
|
111
|
+
interface AuthError {
|
|
112
|
+
code: AuthErrorCode;
|
|
113
|
+
message: string;
|
|
114
|
+
details?: Record<string, unknown>;
|
|
115
|
+
}
|
|
116
|
+
interface AuthConfig {
|
|
117
|
+
/** Base URL for the auth API (e.g., https://pixygon-server.onrender.com/v1) */
|
|
118
|
+
baseUrl: string;
|
|
119
|
+
/** App identifier for token storage keys */
|
|
120
|
+
appId: string;
|
|
121
|
+
/** App display name for branded components */
|
|
122
|
+
appName?: string;
|
|
123
|
+
/** Enable automatic token refresh (default: true) */
|
|
124
|
+
autoRefresh?: boolean;
|
|
125
|
+
/** Time before expiry to trigger refresh in seconds (default: 300 = 5 min) */
|
|
126
|
+
refreshThreshold?: number;
|
|
127
|
+
/** Callback when user logs in */
|
|
128
|
+
onLogin?: (user: User) => void;
|
|
129
|
+
/** Callback when user logs out */
|
|
130
|
+
onLogout?: () => void;
|
|
131
|
+
/** Callback when token is refreshed */
|
|
132
|
+
onTokenRefresh?: (tokens: TokenPair) => void;
|
|
133
|
+
/** Callback when auth error occurs */
|
|
134
|
+
onError?: (error: AuthError) => void;
|
|
135
|
+
/** Storage mechanism (default: localStorage) */
|
|
136
|
+
storage?: AuthStorage;
|
|
137
|
+
/** Enable debug logging (default: false) */
|
|
138
|
+
debug?: boolean;
|
|
139
|
+
}
|
|
140
|
+
interface AuthStorage {
|
|
141
|
+
getItem: (key: string) => string | null | Promise<string | null>;
|
|
142
|
+
setItem: (key: string, value: string) => void | Promise<void>;
|
|
143
|
+
removeItem: (key: string) => void | Promise<void>;
|
|
144
|
+
}
|
|
145
|
+
interface AuthContextValue extends AuthState {
|
|
146
|
+
login: (credentials: LoginRequest) => Promise<LoginResponse>;
|
|
147
|
+
register: (data: RegisterRequest) => Promise<RegisterResponse>;
|
|
148
|
+
logout: () => Promise<void>;
|
|
149
|
+
verify: (data: VerifyRequest) => Promise<VerifyResponse>;
|
|
150
|
+
resendVerification: (data: ResendVerificationRequest) => Promise<ResendVerificationResponse>;
|
|
151
|
+
forgotPassword: (data: ForgotPasswordRequest) => Promise<ForgotPasswordResponse>;
|
|
152
|
+
recoverPassword: (data: RecoverPasswordRequest) => Promise<RecoverPasswordResponse>;
|
|
153
|
+
refreshTokens: () => Promise<void>;
|
|
154
|
+
getAccessToken: () => string | null;
|
|
155
|
+
isAuthenticated: boolean;
|
|
156
|
+
isVerified: boolean;
|
|
157
|
+
hasRole: (role: UserRole | UserRole[]) => boolean;
|
|
158
|
+
config: AuthConfig;
|
|
159
|
+
}
|
|
160
|
+
interface LoginFormProps {
|
|
161
|
+
onSuccess?: (user: User) => void;
|
|
162
|
+
onError?: (error: AuthError) => void;
|
|
163
|
+
onNavigateRegister?: () => void;
|
|
164
|
+
onNavigateForgotPassword?: () => void;
|
|
165
|
+
showBranding?: boolean;
|
|
166
|
+
className?: string;
|
|
167
|
+
}
|
|
168
|
+
interface RegisterFormProps {
|
|
169
|
+
onSuccess?: (user: User) => void;
|
|
170
|
+
onError?: (error: AuthError) => void;
|
|
171
|
+
onNavigateLogin?: () => void;
|
|
172
|
+
showBranding?: boolean;
|
|
173
|
+
className?: string;
|
|
174
|
+
}
|
|
175
|
+
interface VerifyFormProps {
|
|
176
|
+
userName: string;
|
|
177
|
+
onSuccess?: (user: User) => void;
|
|
178
|
+
onError?: (error: AuthError) => void;
|
|
179
|
+
onNavigateLogin?: () => void;
|
|
180
|
+
showBranding?: boolean;
|
|
181
|
+
className?: string;
|
|
182
|
+
}
|
|
183
|
+
interface ForgotPasswordFormProps {
|
|
184
|
+
onSuccess?: () => void;
|
|
185
|
+
onError?: (error: AuthError) => void;
|
|
186
|
+
onNavigateLogin?: () => void;
|
|
187
|
+
showBranding?: boolean;
|
|
188
|
+
className?: string;
|
|
189
|
+
}
|
|
190
|
+
interface PixygonAuthProps {
|
|
191
|
+
mode: 'login' | 'register' | 'verify' | 'forgot-password' | 'recover-password';
|
|
192
|
+
onSuccess?: (user?: User) => void;
|
|
193
|
+
onError?: (error: AuthError) => void;
|
|
194
|
+
onModeChange?: (mode: string) => void;
|
|
195
|
+
userName?: string;
|
|
196
|
+
showBranding?: boolean;
|
|
197
|
+
theme?: 'dark' | 'light';
|
|
198
|
+
className?: string;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export type { AuthContextValue as A, ForgotPasswordRequest as F, LoginRequest as L, PixygonAuthProps as P, RegisterRequest as R, SubscriptionTier as S, TokenPair as T, User as U, VerifyRequest as V, AuthConfig as a, AuthError as b, AuthStatus as c, UserRole as d, AuthStorage as e, LoginResponse as f, RegisterResponse as g, VerifyResponse as h, ResendVerificationRequest as i, ResendVerificationResponse as j, ForgotPasswordResponse as k, RecoverPasswordRequest as l, RecoverPasswordResponse as m, RefreshTokenRequest as n, RefreshTokenResponse as o, AuthErrorCode as p, AuthState as q, ForgotPasswordFormProps as r, LoginFormProps as s, RegisterFormProps as t, TokenPayload as u, VerifyFormProps as v };
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pixygon/auth - Shared Types
|
|
3
|
+
* Type definitions for the Pixygon authentication system
|
|
4
|
+
*/
|
|
5
|
+
type UserRole = 'user' | 'creator' | 'admin' | 'superadmin';
|
|
6
|
+
type SubscriptionTier = 'free' | 'basic' | 'pro' | 'family' | 'enterprise';
|
|
7
|
+
interface User {
|
|
8
|
+
_id: string;
|
|
9
|
+
userName: string;
|
|
10
|
+
email: string;
|
|
11
|
+
isVerified: boolean;
|
|
12
|
+
role: UserRole;
|
|
13
|
+
firstName?: string;
|
|
14
|
+
lastName?: string;
|
|
15
|
+
profilePicture?: string;
|
|
16
|
+
subscriptionTier?: SubscriptionTier;
|
|
17
|
+
stripeCustomerId?: string;
|
|
18
|
+
dailyTokens?: number;
|
|
19
|
+
purchasedTokens?: number;
|
|
20
|
+
bonusTokens?: number;
|
|
21
|
+
subscriptionTokens?: number;
|
|
22
|
+
isChildAccount?: boolean;
|
|
23
|
+
parentUserId?: string;
|
|
24
|
+
apiAccess?: boolean;
|
|
25
|
+
discordUserId?: string;
|
|
26
|
+
twitchUser?: string;
|
|
27
|
+
createdAt?: string;
|
|
28
|
+
updatedAt?: string;
|
|
29
|
+
}
|
|
30
|
+
interface TokenPair {
|
|
31
|
+
accessToken: string;
|
|
32
|
+
refreshToken: string;
|
|
33
|
+
expiresIn: number;
|
|
34
|
+
refreshExpiresIn: number;
|
|
35
|
+
}
|
|
36
|
+
interface TokenPayload {
|
|
37
|
+
id: string;
|
|
38
|
+
role?: UserRole;
|
|
39
|
+
iat: number;
|
|
40
|
+
exp: number;
|
|
41
|
+
}
|
|
42
|
+
type AuthStatus = 'idle' | 'loading' | 'authenticated' | 'unauthenticated' | 'verifying';
|
|
43
|
+
interface AuthState {
|
|
44
|
+
user: User | null;
|
|
45
|
+
accessToken: string | null;
|
|
46
|
+
refreshToken: string | null;
|
|
47
|
+
status: AuthStatus;
|
|
48
|
+
isLoading: boolean;
|
|
49
|
+
error: AuthError | null;
|
|
50
|
+
}
|
|
51
|
+
interface LoginRequest {
|
|
52
|
+
userName: string;
|
|
53
|
+
password: string;
|
|
54
|
+
}
|
|
55
|
+
interface LoginResponse {
|
|
56
|
+
user: User;
|
|
57
|
+
token: string;
|
|
58
|
+
refreshToken?: string;
|
|
59
|
+
expiresIn?: number;
|
|
60
|
+
message?: string;
|
|
61
|
+
}
|
|
62
|
+
interface RegisterRequest {
|
|
63
|
+
userName: string;
|
|
64
|
+
email: string;
|
|
65
|
+
password: string;
|
|
66
|
+
confirmPassword?: string;
|
|
67
|
+
}
|
|
68
|
+
interface RegisterResponse {
|
|
69
|
+
user: User;
|
|
70
|
+
message?: string;
|
|
71
|
+
}
|
|
72
|
+
interface VerifyRequest {
|
|
73
|
+
userName: string;
|
|
74
|
+
verificationCode: string;
|
|
75
|
+
}
|
|
76
|
+
interface VerifyResponse {
|
|
77
|
+
user: User;
|
|
78
|
+
token: string;
|
|
79
|
+
refreshToken?: string;
|
|
80
|
+
message?: string;
|
|
81
|
+
}
|
|
82
|
+
interface ForgotPasswordRequest {
|
|
83
|
+
email: string;
|
|
84
|
+
}
|
|
85
|
+
interface ForgotPasswordResponse {
|
|
86
|
+
message: string;
|
|
87
|
+
}
|
|
88
|
+
interface RecoverPasswordRequest {
|
|
89
|
+
email: string;
|
|
90
|
+
recoveryCode: string;
|
|
91
|
+
newPassword: string;
|
|
92
|
+
}
|
|
93
|
+
interface RecoverPasswordResponse {
|
|
94
|
+
message: string;
|
|
95
|
+
}
|
|
96
|
+
interface RefreshTokenRequest {
|
|
97
|
+
refreshToken: string;
|
|
98
|
+
}
|
|
99
|
+
interface RefreshTokenResponse {
|
|
100
|
+
token: string;
|
|
101
|
+
refreshToken: string;
|
|
102
|
+
expiresIn: number;
|
|
103
|
+
}
|
|
104
|
+
interface ResendVerificationRequest {
|
|
105
|
+
userName: string;
|
|
106
|
+
}
|
|
107
|
+
interface ResendVerificationResponse {
|
|
108
|
+
message: string;
|
|
109
|
+
}
|
|
110
|
+
type AuthErrorCode = 'INVALID_CREDENTIALS' | 'USER_NOT_FOUND' | 'USER_EXISTS' | 'EMAIL_NOT_VERIFIED' | 'INVALID_VERIFICATION_CODE' | 'EXPIRED_VERIFICATION_CODE' | 'INVALID_RECOVERY_CODE' | 'EXPIRED_RECOVERY_CODE' | 'TOKEN_EXPIRED' | 'TOKEN_INVALID' | 'REFRESH_TOKEN_EXPIRED' | 'NETWORK_ERROR' | 'SERVER_ERROR' | 'UNKNOWN_ERROR';
|
|
111
|
+
interface AuthError {
|
|
112
|
+
code: AuthErrorCode;
|
|
113
|
+
message: string;
|
|
114
|
+
details?: Record<string, unknown>;
|
|
115
|
+
}
|
|
116
|
+
interface AuthConfig {
|
|
117
|
+
/** Base URL for the auth API (e.g., https://pixygon-server.onrender.com/v1) */
|
|
118
|
+
baseUrl: string;
|
|
119
|
+
/** App identifier for token storage keys */
|
|
120
|
+
appId: string;
|
|
121
|
+
/** App display name for branded components */
|
|
122
|
+
appName?: string;
|
|
123
|
+
/** Enable automatic token refresh (default: true) */
|
|
124
|
+
autoRefresh?: boolean;
|
|
125
|
+
/** Time before expiry to trigger refresh in seconds (default: 300 = 5 min) */
|
|
126
|
+
refreshThreshold?: number;
|
|
127
|
+
/** Callback when user logs in */
|
|
128
|
+
onLogin?: (user: User) => void;
|
|
129
|
+
/** Callback when user logs out */
|
|
130
|
+
onLogout?: () => void;
|
|
131
|
+
/** Callback when token is refreshed */
|
|
132
|
+
onTokenRefresh?: (tokens: TokenPair) => void;
|
|
133
|
+
/** Callback when auth error occurs */
|
|
134
|
+
onError?: (error: AuthError) => void;
|
|
135
|
+
/** Storage mechanism (default: localStorage) */
|
|
136
|
+
storage?: AuthStorage;
|
|
137
|
+
/** Enable debug logging (default: false) */
|
|
138
|
+
debug?: boolean;
|
|
139
|
+
}
|
|
140
|
+
interface AuthStorage {
|
|
141
|
+
getItem: (key: string) => string | null | Promise<string | null>;
|
|
142
|
+
setItem: (key: string, value: string) => void | Promise<void>;
|
|
143
|
+
removeItem: (key: string) => void | Promise<void>;
|
|
144
|
+
}
|
|
145
|
+
interface AuthContextValue extends AuthState {
|
|
146
|
+
login: (credentials: LoginRequest) => Promise<LoginResponse>;
|
|
147
|
+
register: (data: RegisterRequest) => Promise<RegisterResponse>;
|
|
148
|
+
logout: () => Promise<void>;
|
|
149
|
+
verify: (data: VerifyRequest) => Promise<VerifyResponse>;
|
|
150
|
+
resendVerification: (data: ResendVerificationRequest) => Promise<ResendVerificationResponse>;
|
|
151
|
+
forgotPassword: (data: ForgotPasswordRequest) => Promise<ForgotPasswordResponse>;
|
|
152
|
+
recoverPassword: (data: RecoverPasswordRequest) => Promise<RecoverPasswordResponse>;
|
|
153
|
+
refreshTokens: () => Promise<void>;
|
|
154
|
+
getAccessToken: () => string | null;
|
|
155
|
+
isAuthenticated: boolean;
|
|
156
|
+
isVerified: boolean;
|
|
157
|
+
hasRole: (role: UserRole | UserRole[]) => boolean;
|
|
158
|
+
config: AuthConfig;
|
|
159
|
+
}
|
|
160
|
+
interface LoginFormProps {
|
|
161
|
+
onSuccess?: (user: User) => void;
|
|
162
|
+
onError?: (error: AuthError) => void;
|
|
163
|
+
onNavigateRegister?: () => void;
|
|
164
|
+
onNavigateForgotPassword?: () => void;
|
|
165
|
+
showBranding?: boolean;
|
|
166
|
+
className?: string;
|
|
167
|
+
}
|
|
168
|
+
interface RegisterFormProps {
|
|
169
|
+
onSuccess?: (user: User) => void;
|
|
170
|
+
onError?: (error: AuthError) => void;
|
|
171
|
+
onNavigateLogin?: () => void;
|
|
172
|
+
showBranding?: boolean;
|
|
173
|
+
className?: string;
|
|
174
|
+
}
|
|
175
|
+
interface VerifyFormProps {
|
|
176
|
+
userName: string;
|
|
177
|
+
onSuccess?: (user: User) => void;
|
|
178
|
+
onError?: (error: AuthError) => void;
|
|
179
|
+
onNavigateLogin?: () => void;
|
|
180
|
+
showBranding?: boolean;
|
|
181
|
+
className?: string;
|
|
182
|
+
}
|
|
183
|
+
interface ForgotPasswordFormProps {
|
|
184
|
+
onSuccess?: () => void;
|
|
185
|
+
onError?: (error: AuthError) => void;
|
|
186
|
+
onNavigateLogin?: () => void;
|
|
187
|
+
showBranding?: boolean;
|
|
188
|
+
className?: string;
|
|
189
|
+
}
|
|
190
|
+
interface PixygonAuthProps {
|
|
191
|
+
mode: 'login' | 'register' | 'verify' | 'forgot-password' | 'recover-password';
|
|
192
|
+
onSuccess?: (user?: User) => void;
|
|
193
|
+
onError?: (error: AuthError) => void;
|
|
194
|
+
onModeChange?: (mode: string) => void;
|
|
195
|
+
userName?: string;
|
|
196
|
+
showBranding?: boolean;
|
|
197
|
+
theme?: 'dark' | 'light';
|
|
198
|
+
className?: string;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export type { AuthContextValue as A, ForgotPasswordRequest as F, LoginRequest as L, PixygonAuthProps as P, RegisterRequest as R, SubscriptionTier as S, TokenPair as T, User as U, VerifyRequest as V, AuthConfig as a, AuthError as b, AuthStatus as c, UserRole as d, AuthStorage as e, LoginResponse as f, RegisterResponse as g, VerifyResponse as h, ResendVerificationRequest as i, ResendVerificationResponse as j, ForgotPasswordResponse as k, RecoverPasswordRequest as l, RecoverPasswordResponse as m, RefreshTokenRequest as n, RefreshTokenResponse as o, AuthErrorCode as p, AuthState as q, ForgotPasswordFormProps as r, LoginFormProps as s, RegisterFormProps as t, TokenPayload as u, VerifyFormProps as v };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { A as AuthContextValue, a as AuthConfig, U as User, b as AuthError, c as AuthStatus, d as UserRole, e as AuthStorage, T as TokenPair, L as LoginRequest, f as LoginResponse, R as RegisterRequest, g as RegisterResponse, V as VerifyRequest, h as VerifyResponse, i as ResendVerificationRequest, j as ResendVerificationResponse, F as ForgotPasswordRequest, k as ForgotPasswordResponse, l as RecoverPasswordRequest, m as RecoverPasswordResponse, n as RefreshTokenRequest, o as RefreshTokenResponse } from './index-CIK2MKl9.mjs';
|
|
2
|
+
export { p as AuthErrorCode, q as AuthState, r as ForgotPasswordFormProps, s as LoginFormProps, P as PixygonAuthProps, t as RegisterFormProps, S as SubscriptionTier, u as TokenPayload, v as VerifyFormProps } from './index-CIK2MKl9.mjs';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import * as react from 'react';
|
|
5
|
+
import { ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
declare const AuthContext: react.Context<AuthContextValue | null>;
|
|
8
|
+
interface AuthProviderProps {
|
|
9
|
+
config: AuthConfig;
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
declare function AuthProvider({ config: userConfig, children }: AuthProviderProps): react_jsx_runtime.JSX.Element;
|
|
13
|
+
declare function useAuthContext(): AuthContextValue;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Profile Sync Hook
|
|
17
|
+
* Synchronizes user profile data across Pixygon applications
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
interface UserProfile extends User {
|
|
21
|
+
displayName?: string;
|
|
22
|
+
avatar?: string;
|
|
23
|
+
bio?: string;
|
|
24
|
+
preferences?: Record<string, unknown>;
|
|
25
|
+
linkedApps?: string[];
|
|
26
|
+
lastSyncedAt?: string;
|
|
27
|
+
}
|
|
28
|
+
interface UseProfileSyncReturn {
|
|
29
|
+
/** Current user profile */
|
|
30
|
+
profile: UserProfile | null;
|
|
31
|
+
/** Whether the profile is loading */
|
|
32
|
+
isLoading: boolean;
|
|
33
|
+
/** Whether the profile is syncing */
|
|
34
|
+
isSyncing: boolean;
|
|
35
|
+
/** Error if any */
|
|
36
|
+
error: Error | null;
|
|
37
|
+
/** Update profile */
|
|
38
|
+
updateProfile: (updates: Partial<UserProfile>) => Promise<void>;
|
|
39
|
+
/** Force sync profile from server */
|
|
40
|
+
syncProfile: () => Promise<void>;
|
|
41
|
+
/** Update preferences */
|
|
42
|
+
updatePreferences: (preferences: Record<string, unknown>) => Promise<void>;
|
|
43
|
+
/** Link another app to profile */
|
|
44
|
+
linkApp: (appId: string) => Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Hook to sync user profile across apps
|
|
48
|
+
*/
|
|
49
|
+
declare function useProfileSync(): UseProfileSyncReturn;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @pixygon/auth - Custom Hooks
|
|
53
|
+
* Convenient hooks for accessing auth state and actions
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
interface UseAuthReturn {
|
|
57
|
+
user: User | null;
|
|
58
|
+
status: AuthStatus;
|
|
59
|
+
isLoading: boolean;
|
|
60
|
+
isAuthenticated: boolean;
|
|
61
|
+
isVerified: boolean;
|
|
62
|
+
error: AuthError | null;
|
|
63
|
+
login: ReturnType<typeof useAuthContext>['login'];
|
|
64
|
+
register: ReturnType<typeof useAuthContext>['register'];
|
|
65
|
+
logout: ReturnType<typeof useAuthContext>['logout'];
|
|
66
|
+
verify: ReturnType<typeof useAuthContext>['verify'];
|
|
67
|
+
resendVerification: ReturnType<typeof useAuthContext>['resendVerification'];
|
|
68
|
+
forgotPassword: ReturnType<typeof useAuthContext>['forgotPassword'];
|
|
69
|
+
recoverPassword: ReturnType<typeof useAuthContext>['recoverPassword'];
|
|
70
|
+
hasRole: (role: UserRole | UserRole[]) => boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Main auth hook providing all auth state and actions
|
|
74
|
+
*/
|
|
75
|
+
declare function useAuth(): UseAuthReturn;
|
|
76
|
+
interface UseUserReturn {
|
|
77
|
+
user: User | null;
|
|
78
|
+
isAuthenticated: boolean;
|
|
79
|
+
isVerified: boolean;
|
|
80
|
+
role: UserRole | null;
|
|
81
|
+
hasRole: (role: UserRole | UserRole[]) => boolean;
|
|
82
|
+
userId: string | null;
|
|
83
|
+
userName: string | null;
|
|
84
|
+
email: string | null;
|
|
85
|
+
profilePicture: string | null;
|
|
86
|
+
subscriptionTier: User['subscriptionTier'] | null;
|
|
87
|
+
dailyTokens: number;
|
|
88
|
+
purchasedTokens: number;
|
|
89
|
+
bonusTokens: number;
|
|
90
|
+
subscriptionTokens: number;
|
|
91
|
+
totalTokens: number;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Hook for accessing user data with convenient shortcuts
|
|
95
|
+
*/
|
|
96
|
+
declare function useUser(): UseUserReturn;
|
|
97
|
+
interface UseTokenReturn {
|
|
98
|
+
accessToken: string | null;
|
|
99
|
+
refreshToken: string | null;
|
|
100
|
+
getAccessToken: () => string | null;
|
|
101
|
+
refreshTokens: () => Promise<void>;
|
|
102
|
+
isAuthenticated: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Hook for accessing and managing auth tokens
|
|
106
|
+
*/
|
|
107
|
+
declare function useToken(): UseTokenReturn;
|
|
108
|
+
interface UseAuthStatusReturn {
|
|
109
|
+
status: AuthStatus;
|
|
110
|
+
isIdle: boolean;
|
|
111
|
+
isLoading: boolean;
|
|
112
|
+
isAuthenticated: boolean;
|
|
113
|
+
isUnauthenticated: boolean;
|
|
114
|
+
isVerifying: boolean;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Hook for auth status checks
|
|
118
|
+
*/
|
|
119
|
+
declare function useAuthStatus(): UseAuthStatusReturn;
|
|
120
|
+
interface UseRequireAuthOptions {
|
|
121
|
+
/** Redirect path when not authenticated */
|
|
122
|
+
redirectTo?: string;
|
|
123
|
+
/** Required roles (any of) */
|
|
124
|
+
roles?: UserRole[];
|
|
125
|
+
/** Callback when auth check fails */
|
|
126
|
+
onUnauthorized?: () => void;
|
|
127
|
+
}
|
|
128
|
+
interface UseRequireAuthReturn {
|
|
129
|
+
isAuthorized: boolean;
|
|
130
|
+
isLoading: boolean;
|
|
131
|
+
user: User | null;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Hook for protected routes/components
|
|
135
|
+
* Returns authorization state and user
|
|
136
|
+
*/
|
|
137
|
+
declare function useRequireAuth(options?: UseRequireAuthOptions): UseRequireAuthReturn;
|
|
138
|
+
|
|
139
|
+
interface UseAuthErrorReturn {
|
|
140
|
+
error: AuthError | null;
|
|
141
|
+
hasError: boolean;
|
|
142
|
+
errorMessage: string | null;
|
|
143
|
+
errorCode: AuthError['code'] | null;
|
|
144
|
+
clearError: () => void;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Hook for auth error handling
|
|
148
|
+
*/
|
|
149
|
+
declare function useAuthError(): UseAuthErrorReturn;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @pixygon/auth - Token Storage Utilities
|
|
153
|
+
* Unified storage for auth tokens across all Pixygon apps
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Create a token storage manager for a specific app
|
|
158
|
+
*/
|
|
159
|
+
declare function createTokenStorage(appId: string, storage?: AuthStorage): {
|
|
160
|
+
/**
|
|
161
|
+
* Get the stored access token
|
|
162
|
+
*/
|
|
163
|
+
getAccessToken: () => Promise<string | null>;
|
|
164
|
+
/**
|
|
165
|
+
* Get the stored refresh token
|
|
166
|
+
*/
|
|
167
|
+
getRefreshToken: () => Promise<string | null>;
|
|
168
|
+
/**
|
|
169
|
+
* Get the stored user
|
|
170
|
+
*/
|
|
171
|
+
getUser: () => Promise<User | null>;
|
|
172
|
+
/**
|
|
173
|
+
* Get token expiration time
|
|
174
|
+
*/
|
|
175
|
+
getExpiresAt: () => Promise<number | null>;
|
|
176
|
+
/**
|
|
177
|
+
* Check if access token is expired
|
|
178
|
+
*/
|
|
179
|
+
isTokenExpired: () => Promise<boolean>;
|
|
180
|
+
/**
|
|
181
|
+
* Check if token will expire within threshold (in seconds)
|
|
182
|
+
*/
|
|
183
|
+
willExpireSoon: (thresholdSeconds?: number) => Promise<boolean>;
|
|
184
|
+
/**
|
|
185
|
+
* Store tokens and user data
|
|
186
|
+
*/
|
|
187
|
+
setTokens: (accessToken: string, refreshToken: string | null, expiresIn: number | null, user: User) => Promise<void>;
|
|
188
|
+
/**
|
|
189
|
+
* Update tokens after refresh
|
|
190
|
+
*/
|
|
191
|
+
updateTokens: (tokens: TokenPair) => Promise<void>;
|
|
192
|
+
/**
|
|
193
|
+
* Update user data
|
|
194
|
+
*/
|
|
195
|
+
updateUser: (user: User) => Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* Clear all stored auth data
|
|
198
|
+
*/
|
|
199
|
+
clear: () => Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Get all stored auth data
|
|
202
|
+
*/
|
|
203
|
+
getAll: () => Promise<{
|
|
204
|
+
accessToken: string | null;
|
|
205
|
+
refreshToken: string | null;
|
|
206
|
+
user: any;
|
|
207
|
+
expiresAt: number | null;
|
|
208
|
+
}>;
|
|
209
|
+
};
|
|
210
|
+
type TokenStorage = ReturnType<typeof createTokenStorage>;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @pixygon/auth - API Client
|
|
214
|
+
* Unified API client with automatic token injection and refresh
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
interface AuthApiClient {
|
|
218
|
+
login: (data: LoginRequest) => Promise<LoginResponse>;
|
|
219
|
+
register: (data: RegisterRequest) => Promise<RegisterResponse>;
|
|
220
|
+
verify: (data: VerifyRequest) => Promise<VerifyResponse>;
|
|
221
|
+
resendVerification: (data: ResendVerificationRequest) => Promise<ResendVerificationResponse>;
|
|
222
|
+
forgotPassword: (data: ForgotPasswordRequest) => Promise<ForgotPasswordResponse>;
|
|
223
|
+
recoverPassword: (data: RecoverPasswordRequest) => Promise<RecoverPasswordResponse>;
|
|
224
|
+
refreshToken: (data: RefreshTokenRequest) => Promise<RefreshTokenResponse>;
|
|
225
|
+
getMe: () => Promise<User>;
|
|
226
|
+
updateProfile: (data: Partial<User>) => Promise<User>;
|
|
227
|
+
setAccessToken: (token: string | null) => void;
|
|
228
|
+
getAccessToken: () => string | null;
|
|
229
|
+
request: <T>(endpoint: string, options?: RequestInit) => Promise<T>;
|
|
230
|
+
}
|
|
231
|
+
declare function createAuthApiClient(config: AuthConfig, tokenStorage: TokenStorage): AuthApiClient;
|
|
232
|
+
|
|
233
|
+
export { type AuthApiClient, AuthConfig, AuthContext, AuthContextValue, AuthError, AuthProvider, type AuthProviderProps, AuthStatus, AuthStorage, ForgotPasswordRequest, ForgotPasswordResponse, LoginRequest, LoginResponse, RecoverPasswordRequest, RecoverPasswordResponse, RefreshTokenRequest, RefreshTokenResponse, RegisterRequest, RegisterResponse, ResendVerificationRequest, ResendVerificationResponse, TokenPair, type TokenStorage, type UseAuthErrorReturn, type UseAuthReturn, type UseAuthStatusReturn, type UseProfileSyncReturn, type UseRequireAuthOptions, type UseRequireAuthReturn, type UseTokenReturn, type UseUserReturn, User, type UserProfile, UserRole, VerifyRequest, VerifyResponse, createAuthApiClient, createTokenStorage, useAuth, useAuthContext, useAuthError, useAuthStatus, useProfileSync, useRequireAuth, useToken, useUser };
|