@digilogiclabs/saas-factory-auth 0.2.0 → 0.3.2
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/components/native/index.js +603 -0
- package/dist/components/native/index.js.map +1 -0
- package/dist/components/native/index.mjs +595 -0
- package/dist/components/native/index.mjs.map +1 -0
- package/dist/components/web/index.d.mts +39 -0
- package/dist/components/web/index.d.ts +39 -0
- package/dist/components/web/index.js +417 -0
- package/dist/components/web/index.js.map +1 -0
- package/dist/components/web/index.mjs +411 -0
- package/dist/components/web/index.mjs.map +1 -0
- package/dist/index.d.mts +582 -56
- package/dist/index.d.ts +582 -56
- package/dist/index.js +1833 -91
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1809 -89
- package/dist/index.mjs.map +1 -1
- package/package.json +139 -93
- package/src/components/native/index.d.ts +29 -0
- package/README.md +0 -148
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
export interface AuthFormProps {
|
|
4
|
+
mode?: 'signin' | 'signup';
|
|
5
|
+
onSuccess?: () => void;
|
|
6
|
+
onError?: (error: Error) => void;
|
|
7
|
+
redirectUrl?: string;
|
|
8
|
+
showOAuth?: boolean;
|
|
9
|
+
oauthProviders?: ('google' | 'github' | 'apple')[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface AuthStatusProps {
|
|
13
|
+
showProfileImage?: boolean;
|
|
14
|
+
onSignOut?: () => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ProtectedRouteProps {
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
requiredRoles?: string[];
|
|
20
|
+
fallback?: React.ReactNode;
|
|
21
|
+
loadingComponent?: React.ReactNode;
|
|
22
|
+
onUnauthenticated?: () => void;
|
|
23
|
+
onUnauthorized?: () => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export declare const AuthForm: React.FC<AuthFormProps>;
|
|
27
|
+
export declare const AuthStatus: React.FC<AuthStatusProps>;
|
|
28
|
+
export declare const ProtectedRoute: React.FC<ProtectedRouteProps>;
|
|
29
|
+
|
package/README.md
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
# @digilogiclabs/saas-factory-auth
|
|
2
|
-
|
|
3
|
-
A reusable authentication package built with Next.js, React, and Supabase. This package provides a complete authentication solution for your Next.js applications.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- 🔐 Complete authentication flows
|
|
8
|
-
- Sign in / Sign up
|
|
9
|
-
- Password reset
|
|
10
|
-
- Email verification
|
|
11
|
-
- Magic link authentication
|
|
12
|
-
- 🛡️ Protected routes
|
|
13
|
-
- 📱 Two-factor authentication
|
|
14
|
-
- 👥 Role-based access control
|
|
15
|
-
- 🔑 OAuth provider support
|
|
16
|
-
- 💫 Zero-configuration Supabase integration
|
|
17
|
-
|
|
18
|
-
## Installation
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
npm install @digilogiclabs/saas-factory-auth
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Requirements
|
|
25
|
-
|
|
26
|
-
- Next.js 13 or higher
|
|
27
|
-
- React 18 or higher
|
|
28
|
-
- Supabase project and credentials
|
|
29
|
-
|
|
30
|
-
## Quick Start
|
|
31
|
-
|
|
32
|
-
1. Set up your Supabase environment variables:
|
|
33
|
-
|
|
34
|
-
```env
|
|
35
|
-
NEXT_PUBLIC_SUPABASE_URL=your-supabase-url
|
|
36
|
-
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-supabase-anon-key
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
2. Initialize the authentication provider:
|
|
40
|
-
|
|
41
|
-
```tsx
|
|
42
|
-
// app/providers.tsx
|
|
43
|
-
import { AuthProvider } from '@digilogiclabs/saas-factory-auth';
|
|
44
|
-
|
|
45
|
-
export function Providers({ children }: { children: React.ReactNode }) {
|
|
46
|
-
return <AuthProvider>{children}</AuthProvider>;
|
|
47
|
-
}
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
3. Use authentication hooks in your components:
|
|
51
|
-
|
|
52
|
-
```tsx
|
|
53
|
-
import { useAuth } from '@digilogiclabs/saas-factory-auth';
|
|
54
|
-
|
|
55
|
-
export default function Profile() {
|
|
56
|
-
const { user, signOut } = useAuth();
|
|
57
|
-
|
|
58
|
-
if (!user) return <div>Please sign in</div>;
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<div>
|
|
62
|
-
<h1>Welcome, {user.email}</h1>
|
|
63
|
-
<button onClick={signOut}>Sign Out</button>
|
|
64
|
-
</div>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
## Protected Routes
|
|
70
|
-
|
|
71
|
-
Protect your routes using the middleware:
|
|
72
|
-
|
|
73
|
-
```tsx
|
|
74
|
-
// middleware.ts
|
|
75
|
-
export { authMiddleware as middleware } from '@digilogiclabs/saas-factory-auth';
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
## Role-Based Access Control
|
|
79
|
-
|
|
80
|
-
Define and check user roles:
|
|
81
|
-
|
|
82
|
-
```tsx
|
|
83
|
-
import { useAuth, withRole } from '@digilogiclabs/saas-factory-auth';
|
|
84
|
-
|
|
85
|
-
// Protect component with role
|
|
86
|
-
const AdminDashboard = withRole(['admin'])(() => {
|
|
87
|
-
return <div>Admin Only Content</div>;
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// Use role checks in components
|
|
91
|
-
function Dashboard() {
|
|
92
|
-
const { hasRole } = useAuth();
|
|
93
|
-
|
|
94
|
-
if (hasRole('admin')) {
|
|
95
|
-
return <div>Admin Content</div>;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return <div>User Content</div>;
|
|
99
|
-
}
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## OAuth Providers
|
|
103
|
-
|
|
104
|
-
Enable social authentication:
|
|
105
|
-
|
|
106
|
-
```tsx
|
|
107
|
-
import { OAuthButtons } from '@digilogiclabs/saas-factory-auth';
|
|
108
|
-
|
|
109
|
-
function SignIn() {
|
|
110
|
-
return (
|
|
111
|
-
<div>
|
|
112
|
-
<OAuthButtons providers={['google', 'github']} />
|
|
113
|
-
</div>
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
## API Reference
|
|
119
|
-
|
|
120
|
-
### Hooks
|
|
121
|
-
|
|
122
|
-
- `useAuth()` - Core authentication hook
|
|
123
|
-
- `useUser()` - Current user hook
|
|
124
|
-
- `useRole()` - Role management hook
|
|
125
|
-
- `useProtectedRoute()` - Route protection hook
|
|
126
|
-
|
|
127
|
-
### Components
|
|
128
|
-
|
|
129
|
-
- `<AuthProvider>` - Authentication context provider
|
|
130
|
-
- `<ProtectedRoute>` - Route protection component
|
|
131
|
-
- `<SignIn>` - Sign-in form component
|
|
132
|
-
- `<SignUp>` - Sign-up form component
|
|
133
|
-
- `<OAuthButtons>` - Social authentication buttons
|
|
134
|
-
- `<MagicLink>` - Magic link authentication component
|
|
135
|
-
|
|
136
|
-
### Utilities
|
|
137
|
-
|
|
138
|
-
- `withAuth()` - HOC for protected components
|
|
139
|
-
- `withRole()` - HOC for role-based components
|
|
140
|
-
- `authMiddleware` - Next.js middleware
|
|
141
|
-
|
|
142
|
-
## Contributing
|
|
143
|
-
|
|
144
|
-
We welcome contributions! Please see our [contributing guide](CONTRIBUTING.md) for details.
|
|
145
|
-
|
|
146
|
-
## License
|
|
147
|
-
|
|
148
|
-
MIT © [DigiLogic Labs](https://github.com/DigiLogicLabs)
|