@seamless-auth/react 0.0.1

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 ADDED
@@ -0,0 +1,129 @@
1
+ [![npm version](https://img.shields.io/npm/v/@seamless-auth/react.svg?label=%40seamless-auth%2Freact)](https://www.npmjs.com/package/@seamless-auth/react)
2
+
3
+ # Seamless Auth React
4
+
5
+ A drop-in authentication provider for React applications, designed to handle login, multi-factor authentication, passkeys, and user session validation using your own backend.
6
+
7
+ ## Features
8
+
9
+ - Provides `AuthProvider` context
10
+ - Includes `useAuth()` hook for access to auth state and actions
11
+ - Ships with pre-built login, MFA, and passkey routes
12
+ - Lets consumer apps handle routing via `react-router-dom`
13
+ - Supports automatic session validation on load
14
+
15
+ ---
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install seamless-auth-react
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Usage
26
+
27
+ ### 1. Wrap your app with `AuthProvider`
28
+
29
+ ```tsx
30
+ import { AuthProvider } from "seamless-auth-react";
31
+ import { BrowserRouter } from "react-router-dom";
32
+
33
+ <BrowserRouter>
34
+ <AuthProvider apiHost="https://your.api/">
35
+ <AppRoutes />
36
+ </AuthProvider>
37
+ </BrowserRouter>;
38
+ ```
39
+
40
+ ### 2. Use `useAuth()` to access auth state
41
+
42
+ ```tsx
43
+ import { useAuth } from "seamless-auth-react";
44
+
45
+ const Dashboard = () => {
46
+ const { user, logout } = useAuth();
47
+ return (
48
+ <div>
49
+ Welcome, {user?.email}
50
+ <button onClick={logout}>Logout</button>
51
+ </div>
52
+ );
53
+ };
54
+ ```
55
+
56
+ ### 3. Use `<AuthRoutes />` for handling login/mfa/passkey screens
57
+
58
+ ```tsx
59
+ import { Routes, Route } from "react-router-dom";
60
+ import { useAuth, AuthRoutes } from "seamless-auth-react";
61
+
62
+ const AppRoutes = () => {
63
+ const { isAuthenticated } = useAuth();
64
+
65
+ return (
66
+ <Routes>
67
+ {isAuthenticated ? (
68
+ <Route path="*" element={<Dashboard />} />
69
+ ) : (
70
+ <Route path="*" element={<AuthRoutes />} />
71
+ )}
72
+ </Routes>
73
+ );
74
+ };
75
+ ```
76
+
77
+ > Note: You are responsible for handling route protection and redirects based on `isAuthenticated`.
78
+
79
+ ---
80
+
81
+ ## AuthContext API
82
+
83
+ ### `useAuth()` returns:
84
+
85
+ ```ts
86
+ {
87
+ user: { email: string, roles?: string[] } | null;
88
+ isAuthenticated: boolean;
89
+ logout(): Promise<void>;
90
+ deleteUser(): Promise<void>;
91
+ hasRole(role: string): boolean | undefined;
92
+ }
93
+ ```
94
+
95
+ ---
96
+
97
+ ## Auth Routes Included
98
+
99
+ - `/login`
100
+ - `/mfaLogin`
101
+ - `/passKeyLogin`
102
+ - `/registerPasskey`
103
+ - `/verifyOTP`
104
+
105
+ Each route includes a pre-built UI and expects your backend to expose compatible endpoints.
106
+
107
+ ---
108
+
109
+ ## Customization
110
+
111
+ You can override the included UI screens by:
112
+
113
+ - Copying the component source from the package
114
+ - Creating your own version
115
+ - Replacing the component in your app
116
+
117
+ ---
118
+
119
+ ## Notes
120
+
121
+ - This package **does not** create its own `<BrowserRouter>` or `<Routes>`.
122
+ - It is designed to be fully compatible with your existing routing tree.
123
+ - The `AuthProvider` automatically calls `/users/me` on load to validate session.
124
+
125
+ ---
126
+
127
+ ## License
128
+
129
+ MIT
@@ -0,0 +1,31 @@
1
+ import React, { ReactNode } from "react";
2
+ interface User {
3
+ id: string;
4
+ email: string;
5
+ phone: string;
6
+ roles?: string[];
7
+ }
8
+ type AuthToken = {
9
+ oneTimeToken: string;
10
+ expiresAt: string;
11
+ };
12
+ export interface AuthContextType {
13
+ user: User | null;
14
+ logout: () => void;
15
+ deleteUser: () => void;
16
+ isAuthenticated: boolean;
17
+ hasRole: (role: string) => boolean | undefined;
18
+ apiHost: string;
19
+ token: AuthToken | null;
20
+ }
21
+ /**
22
+ * Returns the current context
23
+ * @returns {AuthContextType} AuthContext
24
+ */
25
+ export declare const useAuth: () => AuthContextType;
26
+ interface AuthProviderProps {
27
+ children: ReactNode;
28
+ apiHost: string;
29
+ }
30
+ export declare const AuthProvider: React.FC<AuthProviderProps>;
31
+ export {};
@@ -0,0 +1 @@
1
+ export declare const AuthRoutes: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ declare const LoadingSpinner: React.FC;
3
+ export default LoadingSpinner;
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ declare const Login: React.FC;
3
+ export default Login;
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ declare const MfaLogin: React.FC;
3
+ export default MfaLogin;
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ declare const PassKeyLogin: React.FC;
3
+ export default PassKeyLogin;
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ declare const RegisterPasskey: React.FC;
3
+ export default RegisterPasskey;
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ interface TermsModalProps {
3
+ isOpen: boolean;
4
+ onClose: () => void;
5
+ }
6
+ declare const TermsModal: React.FC<TermsModalProps>;
7
+ export default TermsModal;
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ export interface ResetPasswordProps {
3
+ apiHost: string;
4
+ setLoading(value: boolean): void;
5
+ validateToken(): void;
6
+ }
7
+ declare const VerifyAccount: React.FC<ResetPasswordProps>;
8
+ export default VerifyAccount;
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ declare const VerifyOTP: React.FC;
3
+ export default VerifyOTP;
@@ -0,0 +1,11 @@
1
+ import { Dispatch, ReactNode, SetStateAction } from "react";
2
+ interface InternalAuthContextType {
3
+ validateToken: () => Promise<void>;
4
+ setLoading: Dispatch<SetStateAction<boolean>>;
5
+ }
6
+ export declare const InternalAuthProvider: ({ value, children, }: {
7
+ value: InternalAuthContextType;
8
+ children: ReactNode;
9
+ }) => import("react/jsx-runtime").JSX.Element;
10
+ export declare const useInternalAuth: () => InternalAuthContextType;
11
+ export {};
@@ -0,0 +1 @@
1
+ export declare const fetchWithAuth: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
@@ -0,0 +1,3 @@
1
+ import { AuthRoutes } from "AuthRoutes";
2
+ import { AuthProvider, useAuth } from "./AuthProvider";
3
+ export { AuthProvider, AuthRoutes, useAuth };