@explita/cloud-auth-client 0.0.1

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.
Files changed (89) hide show
  1. package/README.md +238 -0
  2. package/dist/components/change-password.d.ts +11 -0
  3. package/dist/components/change-password.js +101 -0
  4. package/dist/components/loader.d.ts +2 -0
  5. package/dist/components/loader.js +11 -0
  6. package/dist/components/logged-in.d.ts +3 -0
  7. package/dist/components/logged-in.js +9 -0
  8. package/dist/components/logged-out.d.ts +3 -0
  9. package/dist/components/logged-out.js +9 -0
  10. package/dist/components/login-form.d.ts +2 -0
  11. package/dist/components/login-form.js +102 -0
  12. package/dist/components/message.d.ts +6 -0
  13. package/dist/components/message.js +15 -0
  14. package/dist/components/must-login.d.ts +4 -0
  15. package/dist/components/must-login.js +23 -0
  16. package/dist/components/optional-otp-wrapper.d.ts +3 -0
  17. package/dist/components/optional-otp-wrapper.js +52 -0
  18. package/dist/components/optional-otp.d.ts +3 -0
  19. package/dist/components/optional-otp.js +70 -0
  20. package/dist/components/reset-password.d.ts +8 -0
  21. package/dist/components/reset-password.js +118 -0
  22. package/dist/components/roles.d.ts +6 -0
  23. package/dist/components/roles.js +54 -0
  24. package/dist/components/settings.d.ts +9 -0
  25. package/dist/components/settings.js +26 -0
  26. package/dist/components/signup-form.d.ts +11 -0
  27. package/dist/components/signup-form.js +138 -0
  28. package/dist/components/toggle-2fa.d.ts +7 -0
  29. package/dist/components/toggle-2fa.js +81 -0
  30. package/dist/components/toggle-account-status.d.ts +11 -0
  31. package/dist/components/toggle-account-status.js +91 -0
  32. package/dist/components/ui/button.d.ts +10 -0
  33. package/dist/components/ui/button.js +68 -0
  34. package/dist/components/ui/card.d.ts +9 -0
  35. package/dist/components/ui/card.js +65 -0
  36. package/dist/components/ui/dialog.d.ts +15 -0
  37. package/dist/components/ui/dialog.js +86 -0
  38. package/dist/components/ui/dropdown-menu.d.ts +11 -0
  39. package/dist/components/ui/dropdown-menu.js +63 -0
  40. package/dist/components/ui/input.d.ts +3 -0
  41. package/dist/components/ui/input.js +41 -0
  42. package/dist/components/ui/label.d.ts +3 -0
  43. package/dist/components/ui/label.js +42 -0
  44. package/dist/components/ui/switch.d.ts +4 -0
  45. package/dist/components/ui/switch.js +44 -0
  46. package/dist/components/user-card.d.ts +10 -0
  47. package/dist/components/user-card.js +67 -0
  48. package/dist/components/x-icon.d.ts +2 -0
  49. package/dist/components/x-icon.js +11 -0
  50. package/dist/contexts/auth-provider.d.ts +4 -0
  51. package/dist/contexts/auth-provider.js +208 -0
  52. package/dist/hooks/use-token-refresher.d.ts +2 -0
  53. package/dist/hooks/use-token-refresher.js +118 -0
  54. package/dist/index.d.ts +4 -0
  55. package/dist/index.js +21 -0
  56. package/dist/lib/api-client.d.ts +2 -0
  57. package/dist/lib/api-client.js +38 -0
  58. package/dist/lib/api-server.d.ts +2 -0
  59. package/dist/lib/api-server.js +39 -0
  60. package/dist/lib/api.d.ts +2 -0
  61. package/dist/lib/api.js +10 -0
  62. package/dist/lib/error.d.ts +6 -0
  63. package/dist/lib/error.js +15 -0
  64. package/dist/lib/refresh-helper.d.ts +12 -0
  65. package/dist/lib/refresh-helper.js +82 -0
  66. package/dist/lib/utils.d.ts +21 -0
  67. package/dist/lib/utils.js +148 -0
  68. package/dist/server/cookie.d.ts +1 -0
  69. package/dist/server/cookie.js +29 -0
  70. package/dist/server/index.d.ts +7 -0
  71. package/dist/server/index.js +23 -0
  72. package/dist/server/reset-password.d.ts +3 -0
  73. package/dist/server/reset-password.js +41 -0
  74. package/dist/server/role.d.ts +7 -0
  75. package/dist/server/role.js +63 -0
  76. package/dist/server/server-session.d.ts +8 -0
  77. package/dist/server/server-session.js +31 -0
  78. package/dist/server/server-token.d.ts +4 -0
  79. package/dist/server/server-token.js +39 -0
  80. package/dist/server/toggle-2fa.d.ts +4 -0
  81. package/dist/server/toggle-2fa.js +33 -0
  82. package/dist/server/users-accounts.d.ts +11 -0
  83. package/dist/server/users-accounts.js +94 -0
  84. package/dist/styles.css +1799 -0
  85. package/dist/types.d.ts +284 -0
  86. package/dist/types.js +2 -0
  87. package/dist/ui/index.d.ts +11 -0
  88. package/dist/ui/index.js +27 -0
  89. package/package.json +65 -0
@@ -0,0 +1,284 @@
1
+ export type AuthProviderProps = {
2
+ children: React.ReactNode;
3
+ /**
4
+ * Configuration object for the AuthProvider.
5
+ */
6
+ config?: AuthConfig;
7
+ };
8
+ export type AuthConfig = {
9
+ /**
10
+ * Your application's host (eg: http://localhost:3000).
11
+ * Only useful if the auto-detection fails.
12
+ */
13
+ hostOverride?: string;
14
+ /**
15
+ * The path to the login page default is /login.
16
+ */
17
+ loginPath?: string;
18
+ /**
19
+ * The path to the signup page default is /signup.
20
+ */
21
+ signupPath?: string;
22
+ /**
23
+ * The path to the dashboard page default is /dashboard.
24
+ */
25
+ dashboardPath?: string;
26
+ /**
27
+ * The path to the reset password page default is /forgot-password.
28
+ */
29
+ resetPasswordPath?: string;
30
+ /**
31
+ * Whether to disable the loading screen default is false.
32
+ */
33
+ disableLoading?: boolean;
34
+ /**
35
+ * A callback to run when the user is authenticated.
36
+ */
37
+ onAuthSuccess?: (user: User) => void;
38
+ /**
39
+ * A function to set the cookie value.
40
+ *
41
+ * This function is only useful when you are working in development environment and your app is hosted on a localhost subdomain (eg: http://console.localhost:3000) and you need to access server session from server components or middlewares.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import { setCookie } from "@explita/cloud-auth-client/server";
46
+ *
47
+ * export async function cookieOverrideHandler(cookie?: string) {
48
+ * await setCookie(cookie);
49
+ * }
50
+ * ```
51
+ * @returns void
52
+ */
53
+ cookieOverride?: CookieOverrideFn;
54
+ /**
55
+ * Paths to exclude from authentication.
56
+ */
57
+ excludedPaths?: string[];
58
+ };
59
+ type ComputedRouteContext = {
60
+ loginUrl: string;
61
+ signupUrl: string;
62
+ dashboardUrl: string;
63
+ resetPasswordUrl: string;
64
+ returnPath: string;
65
+ currentPath: string;
66
+ excludedPaths: string[];
67
+ isExcluded: boolean;
68
+ };
69
+ type CookieOverrideFn = (cookie: string | undefined) => Promise<void>;
70
+ export type ApiOptions = {
71
+ method?: "GET" | "POST" | "PUT" | "DELETE";
72
+ body?: Record<string, any>;
73
+ headers?: Record<string, string>;
74
+ [key: string]: any;
75
+ };
76
+ export type NewRole = {
77
+ groupId?: string;
78
+ name: string;
79
+ description?: string;
80
+ permissions?: string[];
81
+ };
82
+ export type Login = {
83
+ email: string;
84
+ password: string;
85
+ authToken?: string | null;
86
+ };
87
+ export type Signup = {
88
+ roleId?: string;
89
+ groupId?: string | null;
90
+ firstName: string;
91
+ lastName: string;
92
+ username?: string;
93
+ email: string;
94
+ password: string;
95
+ confirmPassword: string;
96
+ metaData?: Record<string, any>;
97
+ isSuperAdmin?: boolean;
98
+ };
99
+ export type UpdateUser = Omit<Signup, "password" | "confirmPassword">;
100
+ export type GeneralResponse = {
101
+ status: "failure";
102
+ message: string;
103
+ };
104
+ export type FormResponse<T extends any = any> = {
105
+ status: "validation-error";
106
+ errors: Record<string, string>;
107
+ message: string;
108
+ } | GeneralResponse | {
109
+ status: "success";
110
+ message: string;
111
+ data: T;
112
+ authToken?: string;
113
+ };
114
+ type VerifyUserKey = "email" | "username" | "password";
115
+ export type VerifyUser = {
116
+ key: VerifyUserKey;
117
+ value: string;
118
+ }[];
119
+ export type VerifyUserResponse = {
120
+ success: true;
121
+ data: {
122
+ key: VerifyUserKey;
123
+ value: string;
124
+ status: "available" | "taken";
125
+ message: string;
126
+ }[];
127
+ } | {
128
+ message: string;
129
+ message_slug: string;
130
+ success: false;
131
+ };
132
+ export type ResetPassword = {
133
+ password: string;
134
+ confirmPassword: string;
135
+ };
136
+ export type ResetPasswordWithToken = ResetPassword & {
137
+ token: string;
138
+ };
139
+ export type ResetPasswordWithUserId = ResetPassword & {
140
+ userId: string;
141
+ };
142
+ export type AuthContextType = {
143
+ user: User | null;
144
+ authLoading: boolean;
145
+ isAuthenticated: boolean;
146
+ error: AuthError | null;
147
+ login: (credentials: Login) => Promise<Partial<AuthError> | null>;
148
+ sendPasswordResetRequest: (email: string) => Promise<GeneralResponse>;
149
+ logout: (params?: Record<string, string>) => void;
150
+ hasPermission: (permission: string) => boolean;
151
+ revalidate: () => void;
152
+ computedRouteContext: ComputedRouteContext;
153
+ };
154
+ export type OTPContextReturn = {
155
+ processing: boolean;
156
+ isOpen: boolean;
157
+ open: () => void;
158
+ close: () => void;
159
+ onCanceled?: () => void;
160
+ successMessage: string;
161
+ errorMessage: string;
162
+ otpValue: string;
163
+ setOtpValue: (value: string) => void;
164
+ sendOtp: () => Promise<void>;
165
+ verifyOtp: () => Promise<void>;
166
+ isVerified: boolean;
167
+ id: string;
168
+ sendOnMount?: boolean;
169
+ hasSent: boolean;
170
+ };
171
+ export type OTPContextProps = {
172
+ id?: string;
173
+ userId: string;
174
+ email?: string;
175
+ sendOnMount?: boolean;
176
+ onVerified: (authToken: string, tempRefreshToken?: string) => void;
177
+ onCanceled?: () => void;
178
+ onSend?: () => void;
179
+ onError?: () => void;
180
+ };
181
+ export type Otp = {
182
+ id: string;
183
+ userId: string;
184
+ createdAt: Date;
185
+ serviceId: string | null;
186
+ sentTo: string;
187
+ code: string;
188
+ channel: Channel;
189
+ used: boolean;
190
+ success: boolean;
191
+ reason: Reason | null;
192
+ expiresAt: Date;
193
+ verifiedAt: Date | null;
194
+ };
195
+ export type User = {
196
+ id: string;
197
+ roleId: string | null;
198
+ groupId: string | null;
199
+ email: string;
200
+ username: string | null;
201
+ firstName: string | null;
202
+ lastName: string | null;
203
+ fullName: string | null;
204
+ avatar: string | null;
205
+ with2fa: boolean;
206
+ metaData: Record<string, any>;
207
+ role: Role;
208
+ isSuperAdmin: boolean;
209
+ isActive: boolean;
210
+ isLive: boolean;
211
+ createdAt: string;
212
+ updatedAt: string;
213
+ };
214
+ export type NextAppCookies = {
215
+ get(name: string): {
216
+ value: string;
217
+ } | undefined;
218
+ };
219
+ export type Role = {
220
+ id: string;
221
+ userId: string | null;
222
+ groupId: string | null;
223
+ label: string;
224
+ description: string | null;
225
+ permissions: string[];
226
+ isActive: boolean;
227
+ isLive: boolean;
228
+ createdAt: Date;
229
+ updatedAt: Date;
230
+ isSuperAdmin: boolean;
231
+ };
232
+ export type Project = {
233
+ id: string;
234
+ projectName: string;
235
+ createdAt: string;
236
+ updatedAt: string;
237
+ isActive: boolean;
238
+ slug: string;
239
+ services: Service[];
240
+ };
241
+ export type Service = {
242
+ id: string;
243
+ label: string;
244
+ type: ServiceType;
245
+ publicKey: string;
246
+ privateKey: string;
247
+ isLive: boolean;
248
+ isActive: boolean;
249
+ lastUsed: string | null;
250
+ createdAt: string;
251
+ updatedAt: string;
252
+ envs: {
253
+ privateEnv: string;
254
+ publicEnv: string;
255
+ combined: string;
256
+ };
257
+ slug: string;
258
+ };
259
+ export type AuthError = {
260
+ errors: Record<string, string>;
261
+ message: string;
262
+ message_slug: string;
263
+ status: "failure";
264
+ };
265
+ export type OTPProps = {
266
+ user: User | null;
267
+ onVerified: (authToken: string, tempRefreshToken?: string) => void;
268
+ onCanceled?: () => void;
269
+ };
270
+ export type UseTokenRefresherOptions = {
271
+ refreshTokenRequest: () => Promise<{
272
+ authToken: string;
273
+ tempRefreshToken?: string;
274
+ }>;
275
+ onRefreshFailed?: () => void;
276
+ onTokenRefreshed?: (authToken: string, tempRefreshToken?: string) => void;
277
+ revalidateUserWhenOnline?: () => void;
278
+ config?: AuthConfig;
279
+ };
280
+ export type Status = "ACTIVE" | "INACTIVE";
281
+ export type ServiceType = "auth" | "database" | "otp" | "storage";
282
+ export type Channel = "email" | "sms" | "totp" | "whatsapp";
283
+ export type Reason = "expired" | "invalid" | "success";
284
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ export * from "../components/logged-in";
2
+ export * from "../components/logged-out";
3
+ export * from "../components/user-card";
4
+ export * from "../components/loader";
5
+ export * from "../components/signup-form";
6
+ export * from "../components/login-form";
7
+ export * from "../components/reset-password";
8
+ export * from "../components/change-password";
9
+ export * from "../components/settings";
10
+ export * from "../components/toggle-account-status";
11
+ export * from "../components/toggle-2fa";
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("../components/logged-in"), exports);
18
+ __exportStar(require("../components/logged-out"), exports);
19
+ __exportStar(require("../components/user-card"), exports);
20
+ __exportStar(require("../components/loader"), exports);
21
+ __exportStar(require("../components/signup-form"), exports);
22
+ __exportStar(require("../components/login-form"), exports);
23
+ __exportStar(require("../components/reset-password"), exports);
24
+ __exportStar(require("../components/change-password"), exports);
25
+ __exportStar(require("../components/settings"), exports);
26
+ __exportStar(require("../components/toggle-account-status"), exports);
27
+ __exportStar(require("../components/toggle-2fa"), exports);
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@explita/cloud-auth-client",
3
+ "version": "0.0.1",
4
+ "author": "Explita",
5
+ "license": "MIT",
6
+ "description": "A simple authentication library for React",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/types.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./ui": {
14
+ "default": "./dist/ui/index.js"
15
+ },
16
+ "./server": {
17
+ "default": "./dist/server/index.js"
18
+ },
19
+ "./styles.css": "./dist/styles.css"
20
+ },
21
+ "scripts": {
22
+ "clean": "rimraf dist",
23
+ "build": "npm run clean && tsc",
24
+ "postbuild": "node src/misc/post-build.js",
25
+ "prepublishOnly": "npm run build",
26
+ "styles": "npx @tailwindcss/cli -i ./src/dev-styles.css -o ./src/styles.css --watch"
27
+ },
28
+ "keywords": [
29
+ "auth",
30
+ "authentication",
31
+ "react",
32
+ "session",
33
+ "token",
34
+ "otp"
35
+ ],
36
+ "devDependencies": {
37
+ "@tailwindcss/cli": "^4.1.5",
38
+ "@types/node": "^24",
39
+ "@types/react": "^19",
40
+ "@types/react-dom": "^19",
41
+ "fs-extra": "^11.3.0",
42
+ "rimraf": "^6.0.1",
43
+ "tailwindcss": "^4.1.5",
44
+ "typescript": "^5.8.3"
45
+ },
46
+ "dependencies": {
47
+ "class-variance-authority": "^0.7.1"
48
+ },
49
+ "optionalDependencies": {
50
+ "@explita/cloud-otp-client": "*"
51
+ },
52
+ "peerDependencies": {
53
+ "@radix-ui/react-dialog": "^1",
54
+ "@radix-ui/react-dropdown-menu": "^2",
55
+ "@radix-ui/react-slot": "^1",
56
+ "@radix-ui/react-switch": "^1",
57
+ "react": "^19",
58
+ "react-dom": "^19"
59
+ },
60
+ "files": [
61
+ "dist",
62
+ "README.md",
63
+ "LICENSE"
64
+ ]
65
+ }