@urbackend/react 0.1.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/dist/index.d.mts +118 -0
- package/dist/index.d.ts +118 -0
- package/dist/index.js +964 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +926 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +35 -0
- package/src/components/Toast.tsx +91 -0
- package/src/components/UrAuth.tsx +405 -0
- package/src/components/UrUserButton.tsx +207 -0
- package/src/components.tsx +83 -0
- package/src/context.tsx +140 -0
- package/src/hooks.ts +163 -0
- package/src/index.ts +13 -0
- package/tests/UrAuth.test.tsx +90 -0
- package/tests/context.test.tsx +113 -0
- package/tests/setupTests.ts +1 -0
- package/tsconfig.json +24 -0
- package/tsup.config.ts +11 -0
- package/vitest.config.ts +9 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import * as _urbackend_sdk from '@urbackend/sdk';
|
|
3
|
+
import { UrBackendClient, AuthModule, DatabaseModule, StorageModule, AuthUser, LoginPayload, SignUpPayload, VerifyEmailPayload, ChangePasswordPayload, RequestPasswordResetPayload, ResetPasswordPayload } from '@urbackend/sdk';
|
|
4
|
+
export * from '@urbackend/sdk';
|
|
5
|
+
|
|
6
|
+
interface UrContextValue {
|
|
7
|
+
client: UrBackendClient | null;
|
|
8
|
+
auth: AuthModule | null;
|
|
9
|
+
db: DatabaseModule | null;
|
|
10
|
+
storage: StorageModule | null;
|
|
11
|
+
user: AuthUser | null;
|
|
12
|
+
setUser: React.Dispatch<React.SetStateAction<AuthUser | null>>;
|
|
13
|
+
isInitializing: boolean;
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;
|
|
16
|
+
error: string | null;
|
|
17
|
+
setError: React.Dispatch<React.SetStateAction<string | null>>;
|
|
18
|
+
}
|
|
19
|
+
interface UrProviderProps {
|
|
20
|
+
apiKey: string;
|
|
21
|
+
baseUrl?: string;
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
}
|
|
24
|
+
declare const UrProvider: React.FC<UrProviderProps>;
|
|
25
|
+
declare const useUrContext: () => UrContextValue;
|
|
26
|
+
|
|
27
|
+
declare const useAuth: () => {
|
|
28
|
+
user: _urbackend_sdk.AuthUser | null;
|
|
29
|
+
isInitializing: boolean;
|
|
30
|
+
isLoading: boolean;
|
|
31
|
+
error: string | null;
|
|
32
|
+
isAuthenticated: boolean;
|
|
33
|
+
login: (payload: LoginPayload) => Promise<void>;
|
|
34
|
+
signUp: (payload: SignUpPayload) => Promise<_urbackend_sdk.AuthUser>;
|
|
35
|
+
logout: () => Promise<void>;
|
|
36
|
+
socialLogin: (provider: "google" | "github") => void;
|
|
37
|
+
verifyEmail: (payload: VerifyEmailPayload) => Promise<{
|
|
38
|
+
message: string;
|
|
39
|
+
}>;
|
|
40
|
+
changePassword: (payload: ChangePasswordPayload) => Promise<{
|
|
41
|
+
message: string;
|
|
42
|
+
}>;
|
|
43
|
+
requestPasswordReset: (payload: RequestPasswordResetPayload) => Promise<{
|
|
44
|
+
message: string;
|
|
45
|
+
}>;
|
|
46
|
+
resetPassword: (payload: ResetPasswordPayload) => Promise<{
|
|
47
|
+
message: string;
|
|
48
|
+
}>;
|
|
49
|
+
clearError: () => void;
|
|
50
|
+
authApi: _urbackend_sdk.AuthModule;
|
|
51
|
+
};
|
|
52
|
+
declare const useUser: () => {
|
|
53
|
+
user: _urbackend_sdk.AuthUser | null;
|
|
54
|
+
isInitializing: boolean;
|
|
55
|
+
isLoading: boolean;
|
|
56
|
+
error: string | null;
|
|
57
|
+
isAuthenticated: boolean;
|
|
58
|
+
};
|
|
59
|
+
declare const useDb: () => _urbackend_sdk.DatabaseModule;
|
|
60
|
+
declare const useStorage: () => _urbackend_sdk.StorageModule;
|
|
61
|
+
|
|
62
|
+
interface ProtectedRouteProps {
|
|
63
|
+
children: React.ReactNode;
|
|
64
|
+
redirectTo?: string;
|
|
65
|
+
fallback?: React.ReactNode;
|
|
66
|
+
onRedirect?: () => void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A wrapper component that requires the user to be authenticated.
|
|
70
|
+
* If the user is not authenticated after initialization, they will be redirected,
|
|
71
|
+
* or the fallback will be rendered (or nothing if fallback is not provided and no window redirect occurs).
|
|
72
|
+
*/
|
|
73
|
+
declare const ProtectedRoute: React.FC<ProtectedRouteProps>;
|
|
74
|
+
interface GuestRouteProps {
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
redirectTo?: string;
|
|
77
|
+
fallback?: React.ReactNode;
|
|
78
|
+
onRedirect?: () => void;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A wrapper component that requires the user to NOT be authenticated (e.g. for Login pages).
|
|
82
|
+
* If the user IS authenticated, they will be redirected to the specified route.
|
|
83
|
+
*/
|
|
84
|
+
declare const GuestRoute: React.FC<GuestRouteProps>;
|
|
85
|
+
|
|
86
|
+
interface UrAuthProps {
|
|
87
|
+
providers?: ('google' | 'github')[];
|
|
88
|
+
theme?: 'light' | 'dark';
|
|
89
|
+
onSuccess?: () => void;
|
|
90
|
+
}
|
|
91
|
+
declare const UrAuth: React.FC<UrAuthProps>;
|
|
92
|
+
|
|
93
|
+
interface UrUserButtonProps {
|
|
94
|
+
/**
|
|
95
|
+
* Shape of the profile avatar. Defaults to 'square' as requested.
|
|
96
|
+
*/
|
|
97
|
+
shape?: 'square' | 'circle';
|
|
98
|
+
/**
|
|
99
|
+
* Position of the button on the screen. Defaults to 'top-right'.
|
|
100
|
+
* Use 'inline' if you want to place it within a normal flex/grid layout instead of absolute positioning.
|
|
101
|
+
*/
|
|
102
|
+
position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'inline';
|
|
103
|
+
/**
|
|
104
|
+
* Called when "Profile" is clicked.
|
|
105
|
+
*/
|
|
106
|
+
onProfileClick?: () => void;
|
|
107
|
+
/**
|
|
108
|
+
* Called when "Settings" is clicked.
|
|
109
|
+
*/
|
|
110
|
+
onSettingsClick?: () => void;
|
|
111
|
+
/**
|
|
112
|
+
* Z-index for the fixed container. Defaults to 999.
|
|
113
|
+
*/
|
|
114
|
+
zIndex?: number;
|
|
115
|
+
}
|
|
116
|
+
declare const UrUserButton: React.FC<UrUserButtonProps>;
|
|
117
|
+
|
|
118
|
+
export { GuestRoute, type GuestRouteProps, ProtectedRoute, type ProtectedRouteProps, UrAuth, type UrAuthProps, UrProvider, type UrProviderProps, UrUserButton, type UrUserButtonProps, useAuth, useDb, useStorage, useUrContext, useUser };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import * as _urbackend_sdk from '@urbackend/sdk';
|
|
3
|
+
import { UrBackendClient, AuthModule, DatabaseModule, StorageModule, AuthUser, LoginPayload, SignUpPayload, VerifyEmailPayload, ChangePasswordPayload, RequestPasswordResetPayload, ResetPasswordPayload } from '@urbackend/sdk';
|
|
4
|
+
export * from '@urbackend/sdk';
|
|
5
|
+
|
|
6
|
+
interface UrContextValue {
|
|
7
|
+
client: UrBackendClient | null;
|
|
8
|
+
auth: AuthModule | null;
|
|
9
|
+
db: DatabaseModule | null;
|
|
10
|
+
storage: StorageModule | null;
|
|
11
|
+
user: AuthUser | null;
|
|
12
|
+
setUser: React.Dispatch<React.SetStateAction<AuthUser | null>>;
|
|
13
|
+
isInitializing: boolean;
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;
|
|
16
|
+
error: string | null;
|
|
17
|
+
setError: React.Dispatch<React.SetStateAction<string | null>>;
|
|
18
|
+
}
|
|
19
|
+
interface UrProviderProps {
|
|
20
|
+
apiKey: string;
|
|
21
|
+
baseUrl?: string;
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
}
|
|
24
|
+
declare const UrProvider: React.FC<UrProviderProps>;
|
|
25
|
+
declare const useUrContext: () => UrContextValue;
|
|
26
|
+
|
|
27
|
+
declare const useAuth: () => {
|
|
28
|
+
user: _urbackend_sdk.AuthUser | null;
|
|
29
|
+
isInitializing: boolean;
|
|
30
|
+
isLoading: boolean;
|
|
31
|
+
error: string | null;
|
|
32
|
+
isAuthenticated: boolean;
|
|
33
|
+
login: (payload: LoginPayload) => Promise<void>;
|
|
34
|
+
signUp: (payload: SignUpPayload) => Promise<_urbackend_sdk.AuthUser>;
|
|
35
|
+
logout: () => Promise<void>;
|
|
36
|
+
socialLogin: (provider: "google" | "github") => void;
|
|
37
|
+
verifyEmail: (payload: VerifyEmailPayload) => Promise<{
|
|
38
|
+
message: string;
|
|
39
|
+
}>;
|
|
40
|
+
changePassword: (payload: ChangePasswordPayload) => Promise<{
|
|
41
|
+
message: string;
|
|
42
|
+
}>;
|
|
43
|
+
requestPasswordReset: (payload: RequestPasswordResetPayload) => Promise<{
|
|
44
|
+
message: string;
|
|
45
|
+
}>;
|
|
46
|
+
resetPassword: (payload: ResetPasswordPayload) => Promise<{
|
|
47
|
+
message: string;
|
|
48
|
+
}>;
|
|
49
|
+
clearError: () => void;
|
|
50
|
+
authApi: _urbackend_sdk.AuthModule;
|
|
51
|
+
};
|
|
52
|
+
declare const useUser: () => {
|
|
53
|
+
user: _urbackend_sdk.AuthUser | null;
|
|
54
|
+
isInitializing: boolean;
|
|
55
|
+
isLoading: boolean;
|
|
56
|
+
error: string | null;
|
|
57
|
+
isAuthenticated: boolean;
|
|
58
|
+
};
|
|
59
|
+
declare const useDb: () => _urbackend_sdk.DatabaseModule;
|
|
60
|
+
declare const useStorage: () => _urbackend_sdk.StorageModule;
|
|
61
|
+
|
|
62
|
+
interface ProtectedRouteProps {
|
|
63
|
+
children: React.ReactNode;
|
|
64
|
+
redirectTo?: string;
|
|
65
|
+
fallback?: React.ReactNode;
|
|
66
|
+
onRedirect?: () => void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A wrapper component that requires the user to be authenticated.
|
|
70
|
+
* If the user is not authenticated after initialization, they will be redirected,
|
|
71
|
+
* or the fallback will be rendered (or nothing if fallback is not provided and no window redirect occurs).
|
|
72
|
+
*/
|
|
73
|
+
declare const ProtectedRoute: React.FC<ProtectedRouteProps>;
|
|
74
|
+
interface GuestRouteProps {
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
redirectTo?: string;
|
|
77
|
+
fallback?: React.ReactNode;
|
|
78
|
+
onRedirect?: () => void;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A wrapper component that requires the user to NOT be authenticated (e.g. for Login pages).
|
|
82
|
+
* If the user IS authenticated, they will be redirected to the specified route.
|
|
83
|
+
*/
|
|
84
|
+
declare const GuestRoute: React.FC<GuestRouteProps>;
|
|
85
|
+
|
|
86
|
+
interface UrAuthProps {
|
|
87
|
+
providers?: ('google' | 'github')[];
|
|
88
|
+
theme?: 'light' | 'dark';
|
|
89
|
+
onSuccess?: () => void;
|
|
90
|
+
}
|
|
91
|
+
declare const UrAuth: React.FC<UrAuthProps>;
|
|
92
|
+
|
|
93
|
+
interface UrUserButtonProps {
|
|
94
|
+
/**
|
|
95
|
+
* Shape of the profile avatar. Defaults to 'square' as requested.
|
|
96
|
+
*/
|
|
97
|
+
shape?: 'square' | 'circle';
|
|
98
|
+
/**
|
|
99
|
+
* Position of the button on the screen. Defaults to 'top-right'.
|
|
100
|
+
* Use 'inline' if you want to place it within a normal flex/grid layout instead of absolute positioning.
|
|
101
|
+
*/
|
|
102
|
+
position?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'inline';
|
|
103
|
+
/**
|
|
104
|
+
* Called when "Profile" is clicked.
|
|
105
|
+
*/
|
|
106
|
+
onProfileClick?: () => void;
|
|
107
|
+
/**
|
|
108
|
+
* Called when "Settings" is clicked.
|
|
109
|
+
*/
|
|
110
|
+
onSettingsClick?: () => void;
|
|
111
|
+
/**
|
|
112
|
+
* Z-index for the fixed container. Defaults to 999.
|
|
113
|
+
*/
|
|
114
|
+
zIndex?: number;
|
|
115
|
+
}
|
|
116
|
+
declare const UrUserButton: React.FC<UrUserButtonProps>;
|
|
117
|
+
|
|
118
|
+
export { GuestRoute, type GuestRouteProps, ProtectedRoute, type ProtectedRouteProps, UrAuth, type UrAuthProps, UrProvider, type UrProviderProps, UrUserButton, type UrUserButtonProps, useAuth, useDb, useStorage, useUrContext, useUser };
|