Skip to content

Commit b4a93fb

Browse files
committed
chore: professional readme update and restore package version
1 parent df9bb73 commit b4a93fb

2 files changed

Lines changed: 98 additions & 56 deletions

File tree

README.md

Lines changed: 97 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,134 @@
1+
# @think-grid-labs/react-starter-auth
2+
13
<div align="center">
2-
<a href="#" title="React Starter Authentication">
3-
<img src="https://github.com/akosidencio/react-starter-auth/blob/main/react-starter-auth.png" alt="React Starter Authentication" />
4-
</a>
4+
<img src="https://raw.githubusercontent.com/ThinkGrid-Labs/react-starter-auth/main/react-starter-auth.png" alt="React Starter Authentication" width="600" />
5+
<p>A lightweight, type-safe, and robust authentication suite for React and Next.js.</p>
56
</div>
67

8+
---
79

8-
### Features
10+
### 🚀 Features
11+
- **Type-Safe**: Built with TypeScript, supporting generic User objects for better developer experience.
12+
- **Next.js & React Ready**: Optimized for both client-side and server-side contexts.
13+
- **JWT Centric**: Seamless handling of JWT tokens with automatic expiry checks.
14+
- **Secure by Default**: Strict cookie settings and secure state persistence.
15+
- **Fetcher Integration**: Auto-injects `Authorization` headers into your API requests.
16+
- **Route Protection**: Higher-Order Components and Wrapper components for private routes.
917

10-
Authentication library built for react token based authentication with JWT
11-
- Lightweight and easy to use
12-
- Built for React JS
13-
- Works with Next js
14-
- JWT based authentication
15-
- Secure client authentication
18+
---
1619

17-
### Installation
18-
```jsx
19-
npm install @think-grid-labs/react-starter-auth
20-
21-
yarn @think-grid-labs/react-starter-auth
20+
### 📦 Installation
21+
22+
```bash
23+
# Using pnpm
24+
pnpm add @think-grid-labs/react-starter-auth
25+
26+
# Using npm
27+
npm install @think-grid-labs/react-starter-auth
28+
29+
# Using yarn
30+
yarn add @think-grid-labs/react-starter-auth
2231
```
2332

24-
### Setup
33+
---
2534

26-
```jsx
27-
import { AuthProvider } from '@think-grid-labs/react-starter-auth';
35+
### 🛠️ Setup
36+
37+
Wrap your application in the `AuthProvider`:
2838

29-
<AuthProvider>
30-
<App>
31-
</AuthProvider>
39+
```tsx
40+
import { AuthProvider } from '@think-grid-labs/react-starter-auth';
3241

42+
function App({ children }) {
43+
return (
44+
<AuthProvider>
45+
{children}
46+
</AuthProvider>
47+
);
48+
}
3349
```
34-
### Signin
3550

36-
```jsx
37-
import { useAuth } from '@think-grid-labs/react-starter-auth'
51+
---
3852

39-
const { signIn } = useAuth()
53+
### 🔑 Authentication Flow
4054

41-
const access_token = 'jsjdjdjsxxfd' // response from api
42-
const user {
43-
name: 'john doe',
44-
email: 'example@example.com',
45-
phone: '',
46-
role: ''
47-
}
55+
#### Sign In
56+
```tsx
57+
import { useAuth } from '@think-grid-labs/react-starter-auth';
4858

49-
const authuser = {
50-
token: access_token,
51-
user: user
52-
}
53-
signIn(authuser)
59+
const { signIn } = useAuth();
5460

61+
const handleLogin = async () => {
62+
const { token, user } = await api.login(credentials);
63+
64+
signIn({
65+
token,
66+
user: {
67+
id: user.id,
68+
name: user.display_name,
69+
role: 'admin'
70+
}
71+
});
72+
};
5573
```
5674

57-
### User
58-
59-
```jsx
60-
import { useAuth } from '@think-grid-labs/react-starter-auth'
75+
#### Get User (State)
76+
```tsx
77+
import { useAuth } from '@think-grid-labs/react-starter-auth';
6178

62-
// You can pass a custom User type for better type safety
63-
interface MyUser {
79+
// Define your own User interface for full type safety
80+
interface UserProfile {
81+
id: string;
6482
name: string;
65-
email: string;
83+
role: string;
6684
}
6785

68-
const { isAuthenticated, user } = useAuth<MyUser>()
86+
const { user, isAuthenticated, isLoading } = useAuth<UserProfile>();
87+
88+
console.log(user?.role); // Fully typed!
6989
```
7090

71-
### Fetcher
91+
---
92+
93+
### 📡 Data Fetching
7294

73-
fetcher extends the native Web fetch() API to update each request on the server to set headers Authorizaton Bearer upon sign in.
95+
The `fetcher` utility automatically appends the `Authorization: Bearer <token>` header to your requests if a valid token exists.
7496

75-
```jsx
76-
import { fetcher } from '@think-grid-labs/react-starter-auth'
97+
```tsx
98+
import { fetcher } from '@think-grid-labs/react-starter-auth';
7799

78-
const res = fetcher('https://example.com/api/posts') // GET
79-
const data = await res.json()
100+
const getProfile = async () => {
101+
const response = await fetcher('https://api.example.com/me');
102+
const data = await response.json();
103+
return data;
104+
};
105+
```
106+
107+
---
108+
109+
### 🛡️ Route Protection
80110

81-
const res = fetcher('https://example.com/api/posts', { method: 'POST', body: JSON.stringify(data) }) // POST
82-
const data = await res.json()
111+
#### Using `ProtectedRoute`
112+
```tsx
113+
import { ProtectedRoute } from '@think-grid-labs/react-starter-auth';
114+
import Dashboard from './Dashboard';
83115

116+
// Automatically redirects to /login if not authenticated
117+
<ProtectedRoute component={Dashboard} redirectPath="/login" />
84118
```
85119

86-
### Private route page
120+
#### Using `withAuthentication` (HOC)
121+
```tsx
122+
import { withAuthentication } from '@think-grid-labs/react-starter-auth';
87123

88-
```jsx
89-
import { ProtectedRoute, withAuthentication } from '@think-grid-labs/react-starter-auth'
124+
const PrivatePage = () => <div>Private Content</div>;
90125

126+
export default withAuthentication(PrivatePage);
91127
```
92128

129+
---
130+
131+
### 📄 License
132+
MIT © [ThinkGrid-Labs](https://github.com/ThinkGrid-Labs)
133+
93134

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "@think-grid-labs/react-starter-auth",
3+
"version": "0.1.0",
34
"description": "React Next Starter Authentication",
45
"keywords": [
56
"reactjs",

0 commit comments

Comments
 (0)