@riligar/agents-kit 1.19.0 → 1.20.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/.agent/skills/riligar-dev-auth-react/SKILL.md +28 -22
- package/.agent/skills/riligar-dev-auth-react/assets/auth-loader.jsx +31 -0
- package/.agent/skills/riligar-dev-auth-react/assets/layout.jsx +54 -0
- package/.agent/skills/riligar-dev-auth-react/assets/require-feature.jsx +33 -0
- package/.agent/skills/riligar-dev-auth-react/references/route-protection.md +26 -21
- package/package.json +1 -1
|
@@ -11,10 +11,10 @@ This skill provides a complete workflow for integrating authentication and permi
|
|
|
11
11
|
|
|
12
12
|
### 1. Installation
|
|
13
13
|
|
|
14
|
-
Install the SDK
|
|
14
|
+
Install the SDK and its core dependencies (Mantine & Tabler Icons) using bun:
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
bun add @riligar/auth-react
|
|
17
|
+
bun add @riligar/auth-react @mantine/core @mantine/hooks @mantine/notifications @tabler/icons-react
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
### 2. Environment Variables
|
|
@@ -34,19 +34,29 @@ VITE_AUTH_API_KEY=pk_live_your_public_key
|
|
|
34
34
|
|
|
35
35
|
### 3. AuthProvider Setup
|
|
36
36
|
|
|
37
|
-
Wrap your application (usually in `main.jsx` or `App.jsx`) with the `AuthProvider`.
|
|
37
|
+
Wrap your application (usually in `main.jsx` or `App.jsx`) with the `AuthProvider` and `MantineProvider`.
|
|
38
38
|
|
|
39
39
|
```jsx
|
|
40
40
|
import { AuthProvider } from '@riligar/auth-react'
|
|
41
|
+
import { MantineProvider } from '@mantine/core'
|
|
41
42
|
|
|
42
43
|
ReactDOM.createRoot(document.getElementById('root')).render(
|
|
43
|
-
<
|
|
44
|
-
<
|
|
45
|
-
|
|
44
|
+
<MantineProvider theme={yourTheme}>
|
|
45
|
+
<AuthProvider apiKey={import.meta.env.VITE_AUTH_API_KEY}>
|
|
46
|
+
<App />
|
|
47
|
+
</AuthProvider>
|
|
48
|
+
</MantineProvider>
|
|
46
49
|
)
|
|
47
50
|
```
|
|
48
51
|
|
|
49
|
-
|
|
52
|
+
## Ready-to-Use Templates
|
|
53
|
+
|
|
54
|
+
Use these assets to quickly scaffold a complete authentication flow:
|
|
55
|
+
|
|
56
|
+
- **Routing Architecture**: Comprehensive [routes.jsx](assets/routes.jsx) showing Public vs Protected patterns.
|
|
57
|
+
- **Login & Signup**: Generic [signin.jsx](assets/signin.jsx) and [signup.jsx](assets/signup.jsx) templates.
|
|
58
|
+
- **Email Verification**: [verify-email.jsx](assets/verify-email.jsx) handler.
|
|
59
|
+
- **Utility Wrappers**: [auth-loader.jsx](assets/auth-loader.jsx), [require-feature.jsx](assets/require-feature.jsx), and [layout.jsx](assets/layout.jsx).
|
|
50
60
|
|
|
51
61
|
## Specialized Guides
|
|
52
62
|
|
|
@@ -64,25 +74,21 @@ Use `useAuth()` to access user data and authentication status.
|
|
|
64
74
|
const { user, isAuthenticated, loading } = useAuth()
|
|
65
75
|
```
|
|
66
76
|
|
|
67
|
-
### Adding a Login Form
|
|
68
|
-
|
|
69
|
-
Simply drop the `<SignIn />` component. Use `variant="modal"` if you want it in a popup.
|
|
70
|
-
|
|
71
|
-
```jsx
|
|
72
|
-
<SignIn />
|
|
73
|
-
// or
|
|
74
|
-
<SignIn variant="modal" opened={isOpen} onClose={() => setIsOpen(false)} />
|
|
75
|
-
```
|
|
76
|
-
|
|
77
77
|
### Protecting a Dashboard
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
The recommended pattern is to use the **Protected Group** pattern with React Router as shown in [routes.jsx](assets/routes.jsx).
|
|
80
80
|
|
|
81
81
|
```jsx
|
|
82
|
-
|
|
82
|
+
// Nested routes under <Protect /> guarantee that all sub-routes are guarded.
|
|
83
|
+
<Route element={<Protect fallback={<AuthLoader />} />}>
|
|
83
84
|
<Route
|
|
84
|
-
path="/
|
|
85
|
-
element={<
|
|
86
|
-
|
|
85
|
+
path="/"
|
|
86
|
+
element={<Layout />}
|
|
87
|
+
>
|
|
88
|
+
<Route
|
|
89
|
+
index
|
|
90
|
+
element={<Home />}
|
|
91
|
+
/>
|
|
92
|
+
</Route>
|
|
87
93
|
</Route>
|
|
88
94
|
```
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Center, Loader, Stack, Text } from '@mantine/core'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AuthLoader Component
|
|
5
|
+
*
|
|
6
|
+
* Standard loading screen used during authentication state transitions
|
|
7
|
+
* (e.g., checking tokens on initial load or redirects).
|
|
8
|
+
*/
|
|
9
|
+
export default function AuthLoader() {
|
|
10
|
+
return (
|
|
11
|
+
<Center h="100vh">
|
|
12
|
+
<Stack
|
|
13
|
+
align="center"
|
|
14
|
+
gap="md"
|
|
15
|
+
>
|
|
16
|
+
<Loader
|
|
17
|
+
size="lg"
|
|
18
|
+
variant="dots"
|
|
19
|
+
color="brand"
|
|
20
|
+
/>
|
|
21
|
+
<Text
|
|
22
|
+
size="sm"
|
|
23
|
+
c="dimmed"
|
|
24
|
+
fw={500}
|
|
25
|
+
>
|
|
26
|
+
Verificando acesso...
|
|
27
|
+
</Text>
|
|
28
|
+
</Stack>
|
|
29
|
+
</Center>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AppShell, Burger, Group, Text } from '@mantine/core'
|
|
2
|
+
import { useDisclosure } from '@mantine/hooks'
|
|
3
|
+
import { Outlet } from 'react-router-dom'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Layout Component
|
|
7
|
+
*
|
|
8
|
+
* Standard Dashboard layout using Mantine AppShell.
|
|
9
|
+
* Provides the structure for sidebars, headers, and main content area.
|
|
10
|
+
*/
|
|
11
|
+
export default function Layout() {
|
|
12
|
+
const [opened, { toggle }] = useDisclosure()
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<AppShell
|
|
16
|
+
header={{ height: 60 }}
|
|
17
|
+
navbar={{
|
|
18
|
+
width: 300,
|
|
19
|
+
breakpoint: 'sm',
|
|
20
|
+
collapsed: { mobile: !opened },
|
|
21
|
+
}}
|
|
22
|
+
padding="md"
|
|
23
|
+
>
|
|
24
|
+
<AppShell.Header>
|
|
25
|
+
<Group
|
|
26
|
+
h="100%"
|
|
27
|
+
px="md"
|
|
28
|
+
>
|
|
29
|
+
<Burger
|
|
30
|
+
opened={opened}
|
|
31
|
+
onClick={toggle}
|
|
32
|
+
hiddenFrom="sm"
|
|
33
|
+
size="sm"
|
|
34
|
+
/>
|
|
35
|
+
<Text fw={700}>Dashboard</Text>
|
|
36
|
+
</Group>
|
|
37
|
+
</AppShell.Header>
|
|
38
|
+
|
|
39
|
+
<AppShell.Navbar p="md">
|
|
40
|
+
{/* Navigation links go here */}
|
|
41
|
+
<Text
|
|
42
|
+
size="sm"
|
|
43
|
+
c="dimmed"
|
|
44
|
+
>
|
|
45
|
+
Navigation Menu
|
|
46
|
+
</Text>
|
|
47
|
+
</AppShell.Navbar>
|
|
48
|
+
|
|
49
|
+
<AppShell.Main>
|
|
50
|
+
<Outlet />
|
|
51
|
+
</AppShell.Main>
|
|
52
|
+
</AppShell>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useAuth } from '@riligar/auth-react'
|
|
2
|
+
import { Navigate } from 'react-router-dom'
|
|
3
|
+
import AuthLoader from './auth-loader'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* RequireFeature Wrapper
|
|
7
|
+
*
|
|
8
|
+
* Protects routes based on specific user attributes or feature flags.
|
|
9
|
+
* This is an example of how to extend authentication with business logic.
|
|
10
|
+
*/
|
|
11
|
+
export default function RequireFeature({ children }) {
|
|
12
|
+
const { user, isAuthenticated, loading } = useAuth()
|
|
13
|
+
|
|
14
|
+
if (loading) {
|
|
15
|
+
return <AuthLoader />
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (!isAuthenticated) {
|
|
19
|
+
return (
|
|
20
|
+
<Navigate
|
|
21
|
+
to="/auth/signin"
|
|
22
|
+
replace
|
|
23
|
+
/>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Example logic: Ensure user has a setup complete or a specific role
|
|
28
|
+
// if (!user.onboardingCompleted) {
|
|
29
|
+
// return <Navigate to="/onboarding" replace />
|
|
30
|
+
// }
|
|
31
|
+
|
|
32
|
+
return children
|
|
33
|
+
}
|
|
@@ -13,33 +13,38 @@ Use these components to control access to specific parts of your application.
|
|
|
13
13
|
|
|
14
14
|
## Usage Patterns
|
|
15
15
|
|
|
16
|
-
### Protecting Routes (
|
|
16
|
+
### Protecting Routes (createBrowserRouter)
|
|
17
|
+
|
|
18
|
+
The most robust way to protect routes in a Riligar app is using the **Protected Group** pattern with `createBrowserRouter`. This ensures consistent layout and authentication guards.
|
|
17
19
|
|
|
18
20
|
```jsx
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
21
|
+
import { createBrowserRouter, Navigate } from 'react-router-dom'
|
|
22
|
+
import { Protect } from '@riligar/auth-react'
|
|
23
|
+
import AuthLoader from '../components/auth-loader.jsx'
|
|
24
|
+
import Layout from '../components/layout.jsx'
|
|
25
|
+
|
|
26
|
+
export const router = createBrowserRouter([
|
|
27
|
+
// Public paths
|
|
28
|
+
{ path: '/auth/signin', element: <SignIn /> },
|
|
29
|
+
|
|
30
|
+
// Protected paths
|
|
31
|
+
{
|
|
32
|
+
element: <Protect fallback={<AuthLoader />} />,
|
|
33
|
+
children: [
|
|
34
|
+
{
|
|
35
|
+
path: '/',
|
|
36
|
+
element: <Layout />,
|
|
37
|
+
children: [{ index: true, element: <Dashboard /> }],
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
])
|
|
39
42
|
```
|
|
40
43
|
|
|
41
44
|
### Conditional UI Elements
|
|
42
45
|
|
|
46
|
+
Use these wrappers inside your components (headers, sidebars, etc.) for granular visibility.
|
|
47
|
+
|
|
43
48
|
```jsx
|
|
44
49
|
import { SignedIn, SignedOut, AuthLoading } from '@riligar/auth-react'
|
|
45
50
|
|