react-auth-service 0.0.1 → 0.0.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Auth UI
1
+ # React Auth Service
2
2
 
3
- Reusable React **authentication UI library** with JWT handling, Axios interceptors, and routing helpers.
3
+ Reusable React **authentication library** with JWT handling, Axios interceptors, and routing helpers.
4
4
 
5
5
  > ⚠️ **Routing and navigation are owned by the consumer app**. This library provides UI, auth state, and API handling — not app routes.
6
6
 
@@ -33,18 +33,47 @@ Most apps repeat the same authentication logic:
33
33
  ## Installation
34
34
 
35
35
  ```bash
36
- npm install auth-ui
36
+ npm install react-auth-service
37
37
  ```
38
38
 
39
39
  ---
40
40
 
41
41
  ## Required setup (important)
42
42
 
43
+ Auth Initialization (Mandatory for Consumer Apps)
44
+ Purpose of initAuth()
45
+ ``` tsc
46
+ initAuth() initializes the authentication service and configures the internal Axios instance with the backend API base URL.
47
+
48
+ This allows:
49
+
50
+ Dynamic backend URL configuration
51
+
52
+ Automatic token attachment
53
+
54
+ Refresh token handling
55
+
56
+ Environment-specific backend switching (local / QA / UAT / prod)
57
+
58
+ Without calling initAuth(), the auth service will not work.
59
+
60
+ ⚠️ Mandatory Initialization Step
61
+
62
+ Before rendering the React application, the consumer app must call initAuth() exactly once.
63
+
64
+ ✅ Correct Usage
65
+ import { initAuth } from 'react-auth-service';
66
+
67
+ await initAuth({
68
+ apiBaseUrl: 'http://localhost:9000', // Backend running URL
69
+ });
70
+ ```
71
+
43
72
  ### 1️⃣ Wrap your app with `AuthProvider` and `BrowserRouter`
44
73
 
45
74
  ```tsx
46
75
  import { BrowserRouter } from 'react-router-dom';
47
- import { AuthProvider } from 'auth-ui';
76
+ import { AuthProvider } from 'react-auth-service';
48
77
 
49
78
  <BrowserRouter>
50
79
  <AuthProvider>
@@ -72,7 +101,7 @@ Used for pages like **Login / Signup**.
72
101
  <Route
73
102
  path="/"
74
103
  element={
75
- <PublicRoute>
104
+ <PublicRoute redirectTo="">
76
105
  <AuthForm onLoginSuccess={login} />
77
106
  </PublicRoute>
78
107
  }
@@ -90,7 +119,7 @@ Used for **private pages**.
90
119
  <Route
91
120
  path="/profile"
92
121
  element={
93
- <ProtectedRoute>
122
+ <ProtectedRoute redirectTo="">
94
123
  <UserProfile onLogout={logout} />
95
124
  </ProtectedRoute>
96
125
  }
@@ -140,7 +169,7 @@ This package exports a **preconfigured `axiosInstance`**.
140
169
  ### Usage in consumer app
141
170
 
142
171
  ```ts
143
- import { axiosInstance } from 'auth-ui';
172
+ import { axiosInstance } from 'react-auth-service';
144
173
 
145
174
  axiosInstance.get('/api/orders');
146
175
  ```