@urbackend/react 0.1.0 → 0.2.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 +93 -0
- package/dist/index.d.mts +69 -2
- package/dist/index.d.ts +69 -2
- package/dist/index.js +245 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +246 -82
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -1
- package/src/components/Toast.tsx +0 -91
- package/src/components/UrAuth.tsx +0 -405
- package/src/components/UrUserButton.tsx +0 -207
- package/src/components.tsx +0 -83
- package/src/context.tsx +0 -140
- package/src/hooks.ts +0 -163
- package/src/index.ts +0 -13
- package/tests/UrAuth.test.tsx +0 -90
- package/tests/context.test.tsx +0 -113
- package/tests/setupTests.ts +0 -1
- package/tsconfig.json +0 -24
- package/tsup.config.ts +0 -11
- package/vitest.config.ts +0 -9
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @urbackend/react
|
|
2
|
+
|
|
3
|
+
The official React SDK for [urBackend](https://urbackend.com) — a MongoDB-native Backend as a Service.
|
|
4
|
+
|
|
5
|
+
This SDK provides a `<UrProvider>`, authentication UI components, protected routing, and React hooks (`useUser`, `useAuth`, `useDb`, `useStorage`) to seamlessly integrate urBackend into your React applications.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Install the React SDK alongside the core SDK:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @urbackend/react @urbackend/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
Wrap your application with `<UrProvider>`:
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import React from 'react';
|
|
21
|
+
import ReactDOM from 'react-dom/client';
|
|
22
|
+
import App from './App';
|
|
23
|
+
import { UrProvider } from '@urbackend/react';
|
|
24
|
+
|
|
25
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
26
|
+
<React.StrictMode>
|
|
27
|
+
<UrProvider apiKey="pk_live_your_publishable_key">
|
|
28
|
+
<App />
|
|
29
|
+
</UrProvider>
|
|
30
|
+
</React.StrictMode>
|
|
31
|
+
);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Pre-built Auth UI
|
|
35
|
+
|
|
36
|
+
Use the `<UrAuth>` component to instantly drop in a beautiful authentication screen that handles Email, Password, and Social Providers (Google/GitHub).
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import { UrAuth, GuestRoute } from '@urbackend/react';
|
|
40
|
+
|
|
41
|
+
export default function LoginPage() {
|
|
42
|
+
return (
|
|
43
|
+
<GuestRoute fallback={<div>Loading...</div>} onRedirect={() => window.location.href = '/dashboard'}>
|
|
44
|
+
<UrAuth providers={['google', 'github']} theme="light" />
|
|
45
|
+
</GuestRoute>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Using Hooks & Data
|
|
51
|
+
|
|
52
|
+
Use our hooks to read the session state or fetch data with built-in RLS (Row-Level Security):
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import { useUser, useDb } from '@urbackend/react';
|
|
56
|
+
import { useEffect, useState } from 'react';
|
|
57
|
+
|
|
58
|
+
export default function Dashboard() {
|
|
59
|
+
const { user, logout } = useUser();
|
|
60
|
+
const db = useDb();
|
|
61
|
+
const [products, setProducts] = useState([]);
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
async function fetchProducts() {
|
|
65
|
+
const data = await db.getAll('products', { limit: 10 });
|
|
66
|
+
setProducts(data);
|
|
67
|
+
}
|
|
68
|
+
fetchProducts();
|
|
69
|
+
}, [db]);
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div>
|
|
73
|
+
<h1>Welcome, {user?.name}</h1>
|
|
74
|
+
<button onClick={logout}>Sign Out</button>
|
|
75
|
+
|
|
76
|
+
<h2>Products</h2>
|
|
77
|
+
<ul>
|
|
78
|
+
{products.map(p => (
|
|
79
|
+
<li key={p._id}>{p.name}</li>
|
|
80
|
+
))}
|
|
81
|
+
</ul>
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Documentation
|
|
88
|
+
|
|
89
|
+
For full documentation and advanced usage, visit [docs.ub.bitbros.in](https://docs.ub.bitbros.in).
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -83,9 +83,76 @@ interface GuestRouteProps {
|
|
|
83
83
|
*/
|
|
84
84
|
declare const GuestRoute: React.FC<GuestRouteProps>;
|
|
85
85
|
|
|
86
|
+
type AuthProvider = 'google' | 'github';
|
|
87
|
+
type ThemeMode = 'light' | 'dark';
|
|
88
|
+
interface AuthColors {
|
|
89
|
+
background: string;
|
|
90
|
+
surface: string;
|
|
91
|
+
text: string;
|
|
92
|
+
textMuted: string;
|
|
93
|
+
border: string;
|
|
94
|
+
inputBackground: string;
|
|
95
|
+
primary: string;
|
|
96
|
+
primaryText: string;
|
|
97
|
+
footerBackground: string;
|
|
98
|
+
dividerText: string;
|
|
99
|
+
socialButtonBackground: string;
|
|
100
|
+
}
|
|
101
|
+
interface AuthBranding {
|
|
102
|
+
brandName?: string;
|
|
103
|
+
appName?: string;
|
|
104
|
+
title?: string;
|
|
105
|
+
subtitle?: string;
|
|
106
|
+
logo?: React.ReactNode | string;
|
|
107
|
+
primaryColor?: string;
|
|
108
|
+
}
|
|
109
|
+
interface AuthLabels {
|
|
110
|
+
loginTab: string;
|
|
111
|
+
signupTab: string;
|
|
112
|
+
loginTitle: string;
|
|
113
|
+
signupTitle: string;
|
|
114
|
+
forgotTitle: string;
|
|
115
|
+
resetTitle: string;
|
|
116
|
+
loginButton: string;
|
|
117
|
+
signupButton: string;
|
|
118
|
+
forgotButton: string;
|
|
119
|
+
resetButton: string;
|
|
120
|
+
emailLabel: string;
|
|
121
|
+
emailPlaceholder: string;
|
|
122
|
+
passwordLabel: string;
|
|
123
|
+
passwordPlaceholder: string;
|
|
124
|
+
nameLabel: string;
|
|
125
|
+
namePlaceholder: string;
|
|
126
|
+
otpLabel: string;
|
|
127
|
+
otpPlaceholder: string;
|
|
128
|
+
forgotPasswordLink: string;
|
|
129
|
+
socialDivider: string;
|
|
130
|
+
googleButton: string;
|
|
131
|
+
githubButton: string;
|
|
132
|
+
footerSigninPrompt: string;
|
|
133
|
+
footerSignupPrompt: string;
|
|
134
|
+
footerForgotPrompt: string;
|
|
135
|
+
noAuthMethods: string;
|
|
136
|
+
forgotSubtitle: string;
|
|
137
|
+
resetSubtitle: string;
|
|
138
|
+
signInTitle?: string;
|
|
139
|
+
signUpTitle?: string;
|
|
140
|
+
signInTab?: string;
|
|
141
|
+
signUpTab?: string;
|
|
142
|
+
signInButton?: string;
|
|
143
|
+
signUpButton?: string;
|
|
144
|
+
}
|
|
86
145
|
interface UrAuthProps {
|
|
87
|
-
providers?:
|
|
88
|
-
|
|
146
|
+
providers?: AuthProvider[] | {
|
|
147
|
+
google?: boolean;
|
|
148
|
+
github?: boolean;
|
|
149
|
+
emailPassword?: boolean;
|
|
150
|
+
};
|
|
151
|
+
enableEmailPassword?: boolean;
|
|
152
|
+
theme?: ThemeMode;
|
|
153
|
+
colors?: Partial<AuthColors>;
|
|
154
|
+
branding?: AuthBranding;
|
|
155
|
+
labels?: Partial<AuthLabels>;
|
|
89
156
|
onSuccess?: () => void;
|
|
90
157
|
}
|
|
91
158
|
declare const UrAuth: React.FC<UrAuthProps>;
|
package/dist/index.d.ts
CHANGED
|
@@ -83,9 +83,76 @@ interface GuestRouteProps {
|
|
|
83
83
|
*/
|
|
84
84
|
declare const GuestRoute: React.FC<GuestRouteProps>;
|
|
85
85
|
|
|
86
|
+
type AuthProvider = 'google' | 'github';
|
|
87
|
+
type ThemeMode = 'light' | 'dark';
|
|
88
|
+
interface AuthColors {
|
|
89
|
+
background: string;
|
|
90
|
+
surface: string;
|
|
91
|
+
text: string;
|
|
92
|
+
textMuted: string;
|
|
93
|
+
border: string;
|
|
94
|
+
inputBackground: string;
|
|
95
|
+
primary: string;
|
|
96
|
+
primaryText: string;
|
|
97
|
+
footerBackground: string;
|
|
98
|
+
dividerText: string;
|
|
99
|
+
socialButtonBackground: string;
|
|
100
|
+
}
|
|
101
|
+
interface AuthBranding {
|
|
102
|
+
brandName?: string;
|
|
103
|
+
appName?: string;
|
|
104
|
+
title?: string;
|
|
105
|
+
subtitle?: string;
|
|
106
|
+
logo?: React.ReactNode | string;
|
|
107
|
+
primaryColor?: string;
|
|
108
|
+
}
|
|
109
|
+
interface AuthLabels {
|
|
110
|
+
loginTab: string;
|
|
111
|
+
signupTab: string;
|
|
112
|
+
loginTitle: string;
|
|
113
|
+
signupTitle: string;
|
|
114
|
+
forgotTitle: string;
|
|
115
|
+
resetTitle: string;
|
|
116
|
+
loginButton: string;
|
|
117
|
+
signupButton: string;
|
|
118
|
+
forgotButton: string;
|
|
119
|
+
resetButton: string;
|
|
120
|
+
emailLabel: string;
|
|
121
|
+
emailPlaceholder: string;
|
|
122
|
+
passwordLabel: string;
|
|
123
|
+
passwordPlaceholder: string;
|
|
124
|
+
nameLabel: string;
|
|
125
|
+
namePlaceholder: string;
|
|
126
|
+
otpLabel: string;
|
|
127
|
+
otpPlaceholder: string;
|
|
128
|
+
forgotPasswordLink: string;
|
|
129
|
+
socialDivider: string;
|
|
130
|
+
googleButton: string;
|
|
131
|
+
githubButton: string;
|
|
132
|
+
footerSigninPrompt: string;
|
|
133
|
+
footerSignupPrompt: string;
|
|
134
|
+
footerForgotPrompt: string;
|
|
135
|
+
noAuthMethods: string;
|
|
136
|
+
forgotSubtitle: string;
|
|
137
|
+
resetSubtitle: string;
|
|
138
|
+
signInTitle?: string;
|
|
139
|
+
signUpTitle?: string;
|
|
140
|
+
signInTab?: string;
|
|
141
|
+
signUpTab?: string;
|
|
142
|
+
signInButton?: string;
|
|
143
|
+
signUpButton?: string;
|
|
144
|
+
}
|
|
86
145
|
interface UrAuthProps {
|
|
87
|
-
providers?:
|
|
88
|
-
|
|
146
|
+
providers?: AuthProvider[] | {
|
|
147
|
+
google?: boolean;
|
|
148
|
+
github?: boolean;
|
|
149
|
+
emailPassword?: boolean;
|
|
150
|
+
};
|
|
151
|
+
enableEmailPassword?: boolean;
|
|
152
|
+
theme?: ThemeMode;
|
|
153
|
+
colors?: Partial<AuthColors>;
|
|
154
|
+
branding?: AuthBranding;
|
|
155
|
+
labels?: Partial<AuthLabels>;
|
|
89
156
|
onSuccess?: () => void;
|
|
90
157
|
}
|
|
91
158
|
declare const UrAuth: React.FC<UrAuthProps>;
|