@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/src/index.ts ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @rebasepro/auth
3
+ *
4
+ * Custom JWT authentication package for Rebase with PostgreSQL backend
5
+ */
6
+
7
+ // Types
8
+ export type {
9
+ RebaseAuthController,
10
+ RebaseAuthControllerProps,
11
+ AuthTokens,
12
+ UserInfo,
13
+ AuthResponse,
14
+ RefreshResponse
15
+ } from "./types";
16
+
17
+ export { useRebaseAuthController } from "./hooks/useRebaseAuthController";
18
+ export { useBackendUserManagement } from "./hooks/useBackendUserManagement";
19
+ export type { BackendUserManagementConfig, UserManagement } from "./hooks/useBackendUserManagement";
20
+
21
+ // Components
22
+ export { RebaseLoginView } from "./components/RebaseLoginView";
23
+ export type { RebaseLoginViewProps } from "./components/RebaseLoginView";
24
+ export { createUserManagementAdminViews, UsersView, RolesView } from "./components/AdminViews";
25
+
26
+ // API utilities
27
+ export { setApiUrl, getApiUrl, fetchAuthConfig, AuthApiError } from "./api";
28
+ export type { AuthConfigResponse } from "./api";
package/src/types.ts ADDED
@@ -0,0 +1,102 @@
1
+ import { AuthController, Role, User } from "@rebasepro/core";
2
+
3
+ /**
4
+ * Auth controller that extends the base AuthController
5
+ * with additional methods for email/password and Google login
6
+ */
7
+ export type RebaseAuthController = AuthController & {
8
+ /** Login with Google ID token from frontend Google Sign-In */
9
+ googleLogin: (idToken: string) => Promise<void>;
10
+ /** Login with email and password */
11
+ emailPasswordLogin: (email: string, password: string) => Promise<void>;
12
+ /** Register a new user */
13
+ register: (email: string, password: string, displayName?: string) => Promise<void>;
14
+ /** Skip login (for anonymous access if enabled) */
15
+ skipLogin: () => void;
16
+ /** Whether login was skipped */
17
+ loginSkipped: boolean;
18
+ /** Error from auth provider (login failure details) */
19
+ authProviderError: Error | null;
20
+ /** True when there are no users in the system — first-user bootstrap mode */
21
+ needsSetup: boolean;
22
+ /** Whether new user registration is enabled (always true during setup) */
23
+ registrationEnabled: boolean;
24
+ /** Request password reset email */
25
+ forgotPassword: (email: string) => Promise<void>;
26
+ /** Reset password using token from email */
27
+ resetPassword: (token: string, password: string) => Promise<void>;
28
+ /** Change password for authenticated user */
29
+ changePassword: (oldPassword: string, newPassword: string) => Promise<void>;
30
+ /** Update user profile */
31
+ updateProfile: (displayName?: string, photoURL?: string) => Promise<User>;
32
+ /** Fetch active sessions */
33
+ fetchSessions: () => Promise<Session[]>;
34
+ /** Revoke a session */
35
+ revokeSession: (sessionId: string) => Promise<void>;
36
+ /** Revoke all active sessions */
37
+ revokeAllSessions: () => Promise<void>;
38
+ /** Get internal API URL */
39
+ getApiUrl?: () => string | undefined;
40
+ }
41
+
42
+ /**
43
+ * Props for useRebaseAuthController hook
44
+ */
45
+ export interface RebaseAuthControllerProps {
46
+ /** Base URL of the backend API */
47
+ apiUrl?: string;
48
+ /** Google OAuth client ID (optional, enables Google login) */
49
+ googleClientId?: string;
50
+ /** Callback when user signs out */
51
+ onSignOut?: () => void;
52
+ /** Define roles for a user after login */
53
+ defineRolesFor?: (user: User) => Promise<Role[] | undefined> | Role[] | undefined;
54
+ }
55
+
56
+ /**
57
+ * Auth tokens returned from the backend
58
+ */
59
+ export interface AuthTokens {
60
+ accessToken: string;
61
+ refreshToken: string;
62
+ /** Unix timestamp (ms) when the access token expires */
63
+ accessTokenExpiresAt: number;
64
+ }
65
+
66
+ /**
67
+ * User info from the backend
68
+ */
69
+ export interface UserInfo {
70
+ uid: string;
71
+ email: string;
72
+ displayName?: string | null;
73
+ photoURL?: string | null;
74
+ emailVerified?: boolean;
75
+ roles?: string[];
76
+ }
77
+
78
+ /**
79
+ * Auth response from backend login/register endpoints
80
+ */
81
+ export interface AuthResponse {
82
+ user: UserInfo;
83
+ tokens: AuthTokens;
84
+ }
85
+
86
+ /**
87
+ * Response from token refresh endpoint
88
+ */
89
+ export interface RefreshResponse {
90
+ tokens: AuthTokens;
91
+ }
92
+
93
+ /**
94
+ * Session info from the backend
95
+ */
96
+ export interface Session {
97
+ id: string;
98
+ userAgent?: string;
99
+ ipAddress?: string;
100
+ createdAt: string;
101
+ isCurrentSession?: boolean;
102
+ }