@a-tech.jo/auth-sdk 1.0.0 → 1.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 +129 -0
- package/package.json +3 -2
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# `@a-tech/auth-sdk`
|
|
2
|
+
|
|
3
|
+
A full-stack, customizable authentication SDK providing seamless login, registration, and session management for A-Tech applications.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Quick Start & Integration
|
|
8
|
+
|
|
9
|
+
### 1. Import Global Styles
|
|
10
|
+
Import the pre-compiled CSS file in your root `layout.tsx` or `_app.tsx`:
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
import "@a-tech/auth-sdk/styles.css";
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
### 2. Wrap Application with `AuthProvider`
|
|
20
|
+
|
|
21
|
+
Encapsulate your component tree with the `AuthProvider` to manage global authentication state and token expiration.
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { AuthProvider } from "@a-tech/auth-sdk";
|
|
25
|
+
|
|
26
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
27
|
+
return (
|
|
28
|
+
<html lang="en">
|
|
29
|
+
<body>
|
|
30
|
+
<AuthProvider "local" config="{{" environment: }}>
|
|
31
|
+
{children}
|
|
32
|
+
</AuthProvider>
|
|
33
|
+
</body>
|
|
34
|
+
</html>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
#### Available Environment Configurations
|
|
41
|
+
|
|
42
|
+
| Environment | Key | Description |
|
|
43
|
+
| --- | --- | --- |
|
|
44
|
+
| **Local** | `"local"` | Targets `http://localhost:3000` / local backend services |
|
|
45
|
+
| **Staging** | `"stage"` | Targets staging auth backend (`https://auth.atech-workspace.com`) |
|
|
46
|
+
| **Production** | `"production"` | *(Default)* Targets production auth services |
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
### 3. Embed Authentication Component
|
|
51
|
+
|
|
52
|
+
Render the pre-built, responsive authentication card supporting mode toggling (Login, Register, Forgot Password).
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import { SDKAuthContainer } from "@a-tech/auth-sdk";
|
|
56
|
+
|
|
57
|
+
export default function AuthPage() {
|
|
58
|
+
const handleSuccess = (data: { user: any; token: string }) => {
|
|
59
|
+
console.log("Authenticated successfully:", data);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<div className="flex min-h-screen items-center justify-center">
|
|
64
|
+
<SDKAuthContainer initialMode="login" onSuccess="{handleSuccess}"/>
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### 4. Access User Session (`useAuth` Hook)
|
|
74
|
+
|
|
75
|
+
Access the current user profile, JWT token, and session utilities anywhere within the `AuthProvider` scope:
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
import { useAuth } from "@a-tech/auth-sdk";
|
|
79
|
+
|
|
80
|
+
export default function Dashboard() {
|
|
81
|
+
const { user, token, logout, isExpired } = useAuth();
|
|
82
|
+
|
|
83
|
+
if (!token || isExpired) {
|
|
84
|
+
return <p>Please sign in to access this page.</p>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div>
|
|
89
|
+
<h1>Welcome back, {user?.firstName}!</h1>
|
|
90
|
+
<p>Logged in as: {user?.email}</p>
|
|
91
|
+
<button onClick={logout}>Sign Out</button>
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## How to Update & Publish New Versions
|
|
101
|
+
|
|
102
|
+
When publishing an update to npm, follow standard Semantic Versioning guidelines:
|
|
103
|
+
|
|
104
|
+
### 1. Bump Package Version
|
|
105
|
+
|
|
106
|
+
Choose the appropriate command based on the scope of your changes:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Patch update (Bug fixes: e.g., 1.0.0 -> 1.0.1)
|
|
110
|
+
npm version patch
|
|
111
|
+
|
|
112
|
+
# Minor update (New backward-compatible features: e.g., 1.0.0 -> 1.1.0)
|
|
113
|
+
npm version minor
|
|
114
|
+
|
|
115
|
+
# Major update (Breaking changes: e.g., 1.0.0 -> 2.0.0)
|
|
116
|
+
npm version major
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### 2. Clean, Build, and Publish
|
|
121
|
+
|
|
122
|
+
Run a fresh build and publish to npm using your Granular Access Token:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
# Clean build artifacts and build fresh distribution package
|
|
126
|
+
rm -rf dist *.tgz && npm run build
|
|
127
|
+
|
|
128
|
+
# Publish to npm using your access token
|
|
129
|
+
echo "//registry.npmjs.org/:_authToken=YOUR_NPM_TOKEN" > .npmrc && npm publish --access public ; rm -f .npmrc
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a-tech.jo/auth-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A-Tech Authentication SDK for React and Next.js",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"example": "npm run dev --workspace=example",
|
|
31
31
|
"pack": "npm pack",
|
|
32
32
|
"clean": "rm -rf dist node_modules/.cache *.tgz example/.next",
|
|
33
|
-
"prepublishOnly": "npm run clean && npm run build"
|
|
33
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
34
|
+
"publish": "npm publish --access public"
|
|
34
35
|
},
|
|
35
36
|
"peerDependencies": {
|
|
36
37
|
"react": ">=18.0.0",
|