@rebasepro/auth 0.0.1-canary.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/LICENSE +6 -0
- package/dist/api.d.ts +119 -0
- package/dist/components/AdminViews.d.ts +20 -0
- package/dist/components/RebaseLoginView.d.ts +52 -0
- package/dist/hooks/useBackendUserManagement.d.ts +41 -0
- package/dist/hooks/useRebaseAuthController.d.ts +9 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.es.js +1883 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +1883 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/types.d.ts +95 -0
- package/package.json +48 -0
- package/src/api.ts +328 -0
- package/src/components/AdminViews.tsx +795 -0
- package/src/components/RebaseLoginView.tsx +570 -0
- package/src/hooks/useBackendUserManagement.ts +407 -0
- package/src/hooks/useRebaseAuthController.ts +692 -0
- package/src/index.ts +28 -0
- package/src/types.ts +102 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Source code in this repository is variously licensed under the Business Source
|
|
2
|
+
License 1.1 (BSL), Apache version 2.0 and the MIT license. A copy of each
|
|
3
|
+
license can be found in each one of the packages under the folder packages
|
|
4
|
+
under a file called License. Source code in a given file is licensed under the
|
|
5
|
+
BSL and the copyright belongs to Rebase Authors unless otherwise noted at the
|
|
6
|
+
beginning of the file.
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { AuthResponse, RefreshResponse, Session, UserInfo } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Configure the API base URL
|
|
4
|
+
*/
|
|
5
|
+
export declare function setApiUrl(url: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* Get the current API URL
|
|
8
|
+
*/
|
|
9
|
+
export declare function getApiUrl(): string;
|
|
10
|
+
declare class AuthApiError extends Error {
|
|
11
|
+
code: string;
|
|
12
|
+
constructor(message: string, code: string);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Register a new user with email/password
|
|
16
|
+
*/
|
|
17
|
+
export declare function register(email: string, password: string, displayName?: string): Promise<AuthResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Login with email/password
|
|
20
|
+
*/
|
|
21
|
+
export declare function login(email: string, password: string): Promise<AuthResponse>;
|
|
22
|
+
/**
|
|
23
|
+
* Login with Google ID token
|
|
24
|
+
*/
|
|
25
|
+
export declare function googleLogin(idToken: string): Promise<AuthResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Refresh access token using refresh token
|
|
28
|
+
*/
|
|
29
|
+
export declare function refreshAccessToken(refreshToken: string): Promise<RefreshResponse>;
|
|
30
|
+
/**
|
|
31
|
+
* Logout and invalidate refresh token
|
|
32
|
+
*/
|
|
33
|
+
export declare function logout(refreshToken?: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Get current user info
|
|
36
|
+
*/
|
|
37
|
+
export declare function getCurrentUser(accessToken: string): Promise<{
|
|
38
|
+
user: UserInfo;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Request password reset email
|
|
42
|
+
*/
|
|
43
|
+
export declare function forgotPassword(email: string): Promise<{
|
|
44
|
+
success: boolean;
|
|
45
|
+
message: string;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Reset password using token from email
|
|
49
|
+
*/
|
|
50
|
+
export declare function resetPassword(token: string, password: string): Promise<{
|
|
51
|
+
success: boolean;
|
|
52
|
+
message: string;
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* Change password for authenticated user
|
|
56
|
+
*/
|
|
57
|
+
export declare function changePassword(accessToken: string, oldPassword: string, newPassword: string): Promise<{
|
|
58
|
+
success: boolean;
|
|
59
|
+
message: string;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Send email verification link
|
|
63
|
+
*/
|
|
64
|
+
export declare function sendVerificationEmail(accessToken: string): Promise<{
|
|
65
|
+
success: boolean;
|
|
66
|
+
message: string;
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Verify email address using token
|
|
70
|
+
*/
|
|
71
|
+
export declare function verifyEmail(token: string): Promise<{
|
|
72
|
+
success: boolean;
|
|
73
|
+
message: string;
|
|
74
|
+
}>;
|
|
75
|
+
/**
|
|
76
|
+
* Update current user profile
|
|
77
|
+
*/
|
|
78
|
+
export declare function updateProfile(accessToken: string, displayName?: string, photoURL?: string): Promise<{
|
|
79
|
+
user: UserInfo;
|
|
80
|
+
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Fetch active sessions for current user
|
|
83
|
+
*/
|
|
84
|
+
export declare function fetchSessions(accessToken: string, currentRefreshToken?: string): Promise<{
|
|
85
|
+
sessions: Session[];
|
|
86
|
+
}>;
|
|
87
|
+
/**
|
|
88
|
+
* Revoke a specific session
|
|
89
|
+
*/
|
|
90
|
+
export declare function revokeSession(accessToken: string, sessionId: string): Promise<{
|
|
91
|
+
success: boolean;
|
|
92
|
+
message: string;
|
|
93
|
+
}>;
|
|
94
|
+
/**
|
|
95
|
+
* Revoke all sessions for current user
|
|
96
|
+
*/
|
|
97
|
+
export declare function revokeAllSessions(accessToken: string): Promise<{
|
|
98
|
+
success: boolean;
|
|
99
|
+
message: string;
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Auth config response from the backend
|
|
103
|
+
*/
|
|
104
|
+
export interface AuthConfigResponse {
|
|
105
|
+
/** True when there are no users in the system and first user setup is needed */
|
|
106
|
+
needsSetup: boolean;
|
|
107
|
+
/** Whether new user registration is enabled */
|
|
108
|
+
registrationEnabled: boolean;
|
|
109
|
+
/** Whether Google OAuth is configured */
|
|
110
|
+
googleEnabled: boolean;
|
|
111
|
+
/** Whether email service is configured */
|
|
112
|
+
emailServiceEnabled: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Fetch auth configuration / status from the backend
|
|
116
|
+
* This is an unauthenticated endpoint used to detect bootstrap mode
|
|
117
|
+
*/
|
|
118
|
+
export declare function fetchAuthConfig(): Promise<AuthConfigResponse>;
|
|
119
|
+
export { AuthApiError };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CMSView } from "@rebasepro/core";
|
|
2
|
+
import { UserManagement } from "../hooks/useBackendUserManagement";
|
|
3
|
+
interface AdminViewsProps {
|
|
4
|
+
userManagement: UserManagement;
|
|
5
|
+
apiUrl: string;
|
|
6
|
+
getAuthToken: () => Promise<string>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Create admin views for user and role management
|
|
10
|
+
*/
|
|
11
|
+
export declare function createUserManagementAdminViews({ userManagement, apiUrl, getAuthToken }: AdminViewsProps): CMSView[];
|
|
12
|
+
export declare function UsersView({ userManagement, apiUrl, getAuthToken }: {
|
|
13
|
+
userManagement: UserManagement;
|
|
14
|
+
apiUrl: string;
|
|
15
|
+
getAuthToken: () => Promise<string>;
|
|
16
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export declare function RolesView({ userManagement }: {
|
|
18
|
+
userManagement: UserManagement;
|
|
19
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { RebaseAuthController } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Props for RebaseLoginView
|
|
5
|
+
*/
|
|
6
|
+
export interface RebaseLoginViewProps {
|
|
7
|
+
/**
|
|
8
|
+
* Auth controller from useRebaseAuthController
|
|
9
|
+
*/
|
|
10
|
+
authController: RebaseAuthController;
|
|
11
|
+
/**
|
|
12
|
+
* Path to the logo displayed in the login screen
|
|
13
|
+
*/
|
|
14
|
+
logo?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Enable the skip login button
|
|
17
|
+
*/
|
|
18
|
+
allowSkipLogin?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Disable the login buttons
|
|
21
|
+
*/
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Prevent users from creating new accounts
|
|
25
|
+
*/
|
|
26
|
+
disableSignupScreen?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Display this component when no user is found
|
|
29
|
+
*/
|
|
30
|
+
noUserComponent?: ReactNode;
|
|
31
|
+
/**
|
|
32
|
+
* Display this component below the sign-in buttons
|
|
33
|
+
*/
|
|
34
|
+
additionalComponent?: ReactNode;
|
|
35
|
+
/**
|
|
36
|
+
* Error message when user is not allowed access
|
|
37
|
+
*/
|
|
38
|
+
notAllowedError?: string | Error;
|
|
39
|
+
/**
|
|
40
|
+
* Enable Google login button (requires googleClientId in hook)
|
|
41
|
+
*/
|
|
42
|
+
googleEnabled?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Google client ID for OAuth
|
|
45
|
+
*/
|
|
46
|
+
googleClientId?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Login view component for custom JWT authentication
|
|
50
|
+
* Based on MongoLoginView pattern from @rebasepro/mongodb
|
|
51
|
+
*/
|
|
52
|
+
export declare function RebaseLoginView({ logo, authController, noUserComponent, disableSignupScreen, disabled, notAllowedError, googleEnabled, googleClientId }: RebaseLoginViewProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Role, User } from "@rebasepro/core";
|
|
2
|
+
/**
|
|
3
|
+
* UserManagement interface - compatible with @rebasepro/user_management
|
|
4
|
+
* Defined inline to avoid dependency on that package
|
|
5
|
+
*/
|
|
6
|
+
export interface UserManagement<USER extends User = User> {
|
|
7
|
+
loading: boolean;
|
|
8
|
+
users: USER[];
|
|
9
|
+
saveUser: (user: USER) => Promise<USER>;
|
|
10
|
+
deleteUser: (user: USER) => Promise<void>;
|
|
11
|
+
roles: Role[];
|
|
12
|
+
saveRole: (role: Role) => Promise<void>;
|
|
13
|
+
deleteRole: (role: Role) => Promise<void>;
|
|
14
|
+
isAdmin?: boolean;
|
|
15
|
+
allowDefaultRolesCreation?: boolean;
|
|
16
|
+
includeCollectionConfigPermissions?: boolean;
|
|
17
|
+
defineRolesFor: (user: User) => Promise<Role[] | undefined> | Role[] | undefined;
|
|
18
|
+
getUser: (uid: string) => User | null;
|
|
19
|
+
usersError?: Error;
|
|
20
|
+
rolesError?: Error;
|
|
21
|
+
bootstrapAdmin?: () => Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export interface BackendUserManagementConfig {
|
|
24
|
+
/**
|
|
25
|
+
* Base API URL for the backend
|
|
26
|
+
*/
|
|
27
|
+
apiUrl: string;
|
|
28
|
+
/**
|
|
29
|
+
* Function to get the current auth token
|
|
30
|
+
*/
|
|
31
|
+
getAuthToken: () => Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Current logged-in user
|
|
34
|
+
*/
|
|
35
|
+
currentUser?: User | null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Hook to manage users and roles via backend API
|
|
39
|
+
* Compatible with Rebase UserManagement interface
|
|
40
|
+
*/
|
|
41
|
+
export declare function useBackendUserManagement(config: BackendUserManagementConfig): UserManagement;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RebaseAuthController, RebaseAuthControllerProps } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Auth controller hook for JWT-based authentication
|
|
4
|
+
* with @rebasepro/backend
|
|
5
|
+
*
|
|
6
|
+
* @param props Configuration options
|
|
7
|
+
* @returns RebaseAuthController instance
|
|
8
|
+
*/
|
|
9
|
+
export declare function useRebaseAuthController(props?: RebaseAuthControllerProps): RebaseAuthController;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @rebasepro/auth
|
|
3
|
+
*
|
|
4
|
+
* Custom JWT authentication package for Rebase with PostgreSQL backend
|
|
5
|
+
*/
|
|
6
|
+
export type { RebaseAuthController, RebaseAuthControllerProps, AuthTokens, UserInfo, AuthResponse, RefreshResponse } from "./types";
|
|
7
|
+
export { useRebaseAuthController } from "./hooks/useRebaseAuthController";
|
|
8
|
+
export { useBackendUserManagement } from "./hooks/useBackendUserManagement";
|
|
9
|
+
export type { BackendUserManagementConfig, UserManagement } from "./hooks/useBackendUserManagement";
|
|
10
|
+
export { RebaseLoginView } from "./components/RebaseLoginView";
|
|
11
|
+
export type { RebaseLoginViewProps } from "./components/RebaseLoginView";
|
|
12
|
+
export { createUserManagementAdminViews, UsersView, RolesView } from "./components/AdminViews";
|
|
13
|
+
export { setApiUrl, getApiUrl, fetchAuthConfig, AuthApiError } from "./api";
|
|
14
|
+
export type { AuthConfigResponse } from "./api";
|