@s8lab/sso-client 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 +193 -0
- package/dist/components/CaptchaWidget.d.ts +20 -0
- package/dist/components/ForgotPasswordForm.d.ts +2 -0
- package/dist/components/LoginForm.d.ts +2 -0
- package/dist/components/LogoutButton.d.ts +2 -0
- package/dist/components/ProfileComponent.d.ts +2 -0
- package/dist/components/SignupForm.d.ts +2 -0
- package/dist/components/ui/avatar.d.ts +6 -0
- package/dist/components/ui/button.d.ts +11 -0
- package/dist/components/ui/card.d.ts +8 -0
- package/dist/components/ui/checkbox.d.ts +4 -0
- package/dist/components/ui/input.d.ts +5 -0
- package/dist/components/ui/label.d.ts +5 -0
- package/dist/components/ui/separator.d.ts +4 -0
- package/dist/context/AuthContext.d.ts +4 -0
- package/dist/index.cjs +100 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +9917 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/captchaV3.d.ts +12 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/types/index.d.ts +148 -0
- package/package.json +78 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
grecaptcha: {
|
|
4
|
+
ready: (cb: () => void) => void;
|
|
5
|
+
execute: (siteKey: string, options: {
|
|
6
|
+
action: string;
|
|
7
|
+
}) => Promise<string>;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export declare function loadRecaptchaV3Script(siteKey: string): void;
|
|
12
|
+
export declare function executeRecaptchaV3(siteKey: string, action: string): Promise<string>;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export interface CaptchaConfig {
|
|
3
|
+
enabled: boolean;
|
|
4
|
+
/** "recaptcha" (Google) or "hcaptcha" */
|
|
5
|
+
provider?: "recaptcha" | "hcaptcha";
|
|
6
|
+
/** "v2" = checkbox widget, "v3" = invisible/score-based */
|
|
7
|
+
version?: "v2" | "v3";
|
|
8
|
+
siteKey?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface OAuthProvider {
|
|
11
|
+
/** e.g. "google" | "github" | "facebook" */
|
|
12
|
+
provider: string;
|
|
13
|
+
/** Display label. Defaults to capitalised provider name */
|
|
14
|
+
label?: string;
|
|
15
|
+
/** Full OAuth redirect URL returned by your server */
|
|
16
|
+
url: string;
|
|
17
|
+
}
|
|
18
|
+
export interface AuthConfig {
|
|
19
|
+
logoUrl?: string;
|
|
20
|
+
allowSignup: boolean;
|
|
21
|
+
allowMagicLink?: boolean;
|
|
22
|
+
captcha: CaptchaConfig;
|
|
23
|
+
privacyPolicyUrl?: string;
|
|
24
|
+
termsOfServiceUrl?: string;
|
|
25
|
+
oauthProviders?: OAuthProvider[];
|
|
26
|
+
}
|
|
27
|
+
export interface AuthConfigContextValue {
|
|
28
|
+
config: AuthConfig | null;
|
|
29
|
+
configLoading: boolean;
|
|
30
|
+
apiUrl: string;
|
|
31
|
+
}
|
|
32
|
+
export interface User {
|
|
33
|
+
id: string;
|
|
34
|
+
email: string;
|
|
35
|
+
firstName: string;
|
|
36
|
+
lastName: string;
|
|
37
|
+
whatsappNumber?: string;
|
|
38
|
+
avatarUrl?: string;
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
}
|
|
41
|
+
export interface AuthTokens {
|
|
42
|
+
accessToken: string;
|
|
43
|
+
refreshToken?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface AuthState {
|
|
46
|
+
user: User | null;
|
|
47
|
+
tokens: AuthTokens | null;
|
|
48
|
+
isLoading: boolean;
|
|
49
|
+
isAuthenticated: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface LoginPayload {
|
|
52
|
+
email: string;
|
|
53
|
+
password: string;
|
|
54
|
+
captchaToken: string;
|
|
55
|
+
rememberMe?: boolean;
|
|
56
|
+
}
|
|
57
|
+
export interface SignupPayload {
|
|
58
|
+
firstName: string;
|
|
59
|
+
lastName: string;
|
|
60
|
+
email: string;
|
|
61
|
+
password: string;
|
|
62
|
+
whatsappNumber?: string;
|
|
63
|
+
captchaToken: string;
|
|
64
|
+
}
|
|
65
|
+
export interface ForgotPasswordPayload {
|
|
66
|
+
email: string;
|
|
67
|
+
captchaToken: string;
|
|
68
|
+
}
|
|
69
|
+
export interface MagicLinkPayload {
|
|
70
|
+
email: string;
|
|
71
|
+
captchaToken: string;
|
|
72
|
+
}
|
|
73
|
+
export interface AuthContextValue extends AuthState {
|
|
74
|
+
login: (payload: LoginPayload) => Promise<void>;
|
|
75
|
+
signup: (payload: SignupPayload) => Promise<void>;
|
|
76
|
+
logout: () => Promise<void>;
|
|
77
|
+
forgotPassword: (payload: ForgotPasswordPayload) => Promise<void>;
|
|
78
|
+
sendMagicLink: (payload: MagicLinkPayload) => Promise<void>;
|
|
79
|
+
updateUser: (user: Partial<User>) => void;
|
|
80
|
+
}
|
|
81
|
+
export interface AuthProviderProps {
|
|
82
|
+
children: React.ReactNode;
|
|
83
|
+
/**
|
|
84
|
+
* Base URL of your SSO API server.
|
|
85
|
+
* Expected endpoints:
|
|
86
|
+
* GET /auth/config (with X-Project-Id header)
|
|
87
|
+
* POST /auth/login
|
|
88
|
+
* POST /auth/signup
|
|
89
|
+
* POST /auth/logout
|
|
90
|
+
* POST /auth/forgot-password
|
|
91
|
+
* POST /auth/magic-link
|
|
92
|
+
* GET /auth/me
|
|
93
|
+
*/
|
|
94
|
+
apiUrl: string;
|
|
95
|
+
/** Project ID sent as X-Project-Id header when loading auth config */
|
|
96
|
+
projectId: string;
|
|
97
|
+
/** localStorage key prefix for tokens. Default: "sso" */
|
|
98
|
+
storageKeyPrefix?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Custom fetch handler — override for custom headers, interceptors, etc.
|
|
101
|
+
* Must return the parsed JSON response (or undefined for 204).
|
|
102
|
+
*/
|
|
103
|
+
fetcher?: <T>(url: string, init: RequestInit) => Promise<T>;
|
|
104
|
+
}
|
|
105
|
+
export interface LoginFormProps {
|
|
106
|
+
/** Extra CSS classes applied to the outer Card */
|
|
107
|
+
className?: string;
|
|
108
|
+
/** Called after a successful login */
|
|
109
|
+
onSuccess?: (user: User) => void;
|
|
110
|
+
/** Called on login or config error */
|
|
111
|
+
onError?: (error: Error) => void;
|
|
112
|
+
/** href for the "Forgot password?" link */
|
|
113
|
+
forgotPasswordUrl?: string;
|
|
114
|
+
/** href for the "Sign up" link (only shown when config.allowSignup is true) */
|
|
115
|
+
signupUrl?: string;
|
|
116
|
+
/** Override the page title. Default: "Sign in to your account" */
|
|
117
|
+
title?: string;
|
|
118
|
+
}
|
|
119
|
+
export interface SignupFormProps {
|
|
120
|
+
className?: string;
|
|
121
|
+
onSuccess?: (user: User) => void;
|
|
122
|
+
onError?: (error: Error) => void;
|
|
123
|
+
/** href for the "Sign in" link */
|
|
124
|
+
loginUrl?: string;
|
|
125
|
+
title?: string;
|
|
126
|
+
}
|
|
127
|
+
export interface ForgotPasswordFormProps {
|
|
128
|
+
className?: string;
|
|
129
|
+
onSuccess?: () => void;
|
|
130
|
+
onError?: (error: Error) => void;
|
|
131
|
+
loginUrl?: string;
|
|
132
|
+
title?: string;
|
|
133
|
+
}
|
|
134
|
+
export interface LogoutButtonProps {
|
|
135
|
+
className?: string;
|
|
136
|
+
onSuccess?: () => void;
|
|
137
|
+
onError?: (error: Error) => void;
|
|
138
|
+
label?: string;
|
|
139
|
+
children?: (props: {
|
|
140
|
+
isLoading: boolean;
|
|
141
|
+
}) => React.ReactNode;
|
|
142
|
+
}
|
|
143
|
+
export interface ProfileComponentProps {
|
|
144
|
+
className?: string;
|
|
145
|
+
onEditProfile?: (user: User) => void;
|
|
146
|
+
showLogout?: boolean;
|
|
147
|
+
onLogoutSuccess?: () => void;
|
|
148
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@s8lab/sso-client",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "SSO authentication components for React — Login, Signup, ForgotPassword, Logout, Profile with Google reCAPTCHA and shadcn UI",
|
|
5
|
+
"author": "S8 Lab",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"module": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./styles.css": "./dist/styles.css"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"dev": "vite",
|
|
24
|
+
"build": "tsc && vite build",
|
|
25
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
26
|
+
"preview": "vite preview",
|
|
27
|
+
"prepublishOnly": "npm run build"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": "^18.0.0",
|
|
31
|
+
"react-dom": "^18.0.0"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@hookform/resolvers": "^3.9.0",
|
|
35
|
+
"@hcaptcha/react-hcaptcha": "^1.1.1",
|
|
36
|
+
"@radix-ui/react-avatar": "^1.1.1",
|
|
37
|
+
"@radix-ui/react-checkbox": "^1.1.2",
|
|
38
|
+
"@radix-ui/react-label": "^2.1.0",
|
|
39
|
+
"@radix-ui/react-separator": "^1.1.0",
|
|
40
|
+
"@radix-ui/react-slot": "^1.1.0",
|
|
41
|
+
"class-variance-authority": "^0.7.1",
|
|
42
|
+
"clsx": "^2.1.1",
|
|
43
|
+
"lucide-react": "^0.468.0",
|
|
44
|
+
"react-google-recaptcha": "^3.1.0",
|
|
45
|
+
"react-hook-form": "^7.54.0",
|
|
46
|
+
"tailwind-merge": "^2.5.5",
|
|
47
|
+
"zod": "^3.23.8"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "^22.10.2",
|
|
51
|
+
"@types/react": "^18.3.18",
|
|
52
|
+
"@types/react-dom": "^18.3.5",
|
|
53
|
+
"@types/react-google-recaptcha": "^2.1.9",
|
|
54
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
55
|
+
"autoprefixer": "^10.4.20",
|
|
56
|
+
"eslint": "^9.17.0",
|
|
57
|
+
"postcss": "^8.4.49",
|
|
58
|
+
"tailwindcss": "^3.4.17",
|
|
59
|
+
"typescript": "^5.7.2",
|
|
60
|
+
"vite": "^6.0.5",
|
|
61
|
+
"vite-plugin-dts": "^4.3.0",
|
|
62
|
+
"vite-plugin-lib-inject-css": "^2.1.1"
|
|
63
|
+
},
|
|
64
|
+
"keywords": [
|
|
65
|
+
"sso",
|
|
66
|
+
"auth",
|
|
67
|
+
"login",
|
|
68
|
+
"signup",
|
|
69
|
+
"react",
|
|
70
|
+
"shadcn",
|
|
71
|
+
"recaptcha",
|
|
72
|
+
"authentication"
|
|
73
|
+
],
|
|
74
|
+
"repository": {
|
|
75
|
+
"type": "git",
|
|
76
|
+
"url": "https://github.com/avasarhub/sso-client-sdk"
|
|
77
|
+
}
|
|
78
|
+
}
|