@mavenmm/teamwork-auth 2.0.5 → 2.1.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/CLAUDE.md +128 -10
- package/package.json +1 -1
package/CLAUDE.md
CHANGED
|
@@ -47,10 +47,12 @@ The package automatically detects the environment:
|
|
|
47
47
|
```bash
|
|
48
48
|
# In your app's .env file:
|
|
49
49
|
VITE_CLIENT_ID=<teamwork_oauth_client_id>
|
|
50
|
-
VITE_REDIRECT_URI=http://localhost:3000
|
|
51
|
-
VITE_DOMAIN_KEY=
|
|
50
|
+
VITE_REDIRECT_URI=http://localhost:3000 # Or your port (5173, 8080, etc.)
|
|
51
|
+
VITE_DOMAIN_KEY=dev_localhost_shared # Shared key for ALL localhost ports
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
+
**Important:** All localhost ports (3000, 5173, 5174, 8080) use the same `dev_localhost_shared` key.
|
|
55
|
+
|
|
54
56
|
### For Production
|
|
55
57
|
```bash
|
|
56
58
|
# In your deployed app's environment:
|
|
@@ -176,8 +178,8 @@ npm install @mavenmm/teamwork-auth
|
|
|
176
178
|
Create `.env` file:
|
|
177
179
|
```bash
|
|
178
180
|
VITE_CLIENT_ID=<your_teamwork_client_id>
|
|
179
|
-
VITE_REDIRECT_URI=http://localhost:3000
|
|
180
|
-
VITE_DOMAIN_KEY=
|
|
181
|
+
VITE_REDIRECT_URI=http://localhost:3000 # Or your dev port
|
|
182
|
+
VITE_DOMAIN_KEY=dev_localhost_shared
|
|
181
183
|
```
|
|
182
184
|
|
|
183
185
|
3. **Start local auth service:**
|
|
@@ -203,7 +205,8 @@ import { useTeamworkAuth, Login } from '@mavenmm/teamwork-auth';
|
|
|
203
205
|
|
|
204
206
|
**Issue: "Invalid domain key"**
|
|
205
207
|
- Verify `VITE_DOMAIN_KEY` in your app matches `DEV_KEY` in auth service
|
|
206
|
-
- Both should be
|
|
208
|
+
- For localhost: Both should be `dev_localhost_shared` (all ports use same key)
|
|
209
|
+
- For production: Use unique key provided by auth.mavenmm.com admin
|
|
207
210
|
|
|
208
211
|
**Issue: "CORS errors"**
|
|
209
212
|
- Ensure your app's origin is registered in auth service's domain registry
|
|
@@ -226,6 +229,20 @@ import { useTeamworkAuth, Login } from '@mavenmm/teamwork-auth';
|
|
|
226
229
|
- Check browser console for "Failed to fetch user data" errors
|
|
227
230
|
- Verify auth service /user endpoint is deployed and working
|
|
228
231
|
|
|
232
|
+
**Issue: "Cookies not being set/validated" (Migration)**
|
|
233
|
+
- Ensure `VITE_DOMAIN_KEY` matches the expected key in auth service domain registry
|
|
234
|
+
- For localhost: Use `dev_localhost_shared` (not port-specific keys)
|
|
235
|
+
- Clear browser cookies and localStorage, then login again
|
|
236
|
+
- Check auth service logs for "Invalid domain key" or "Domain validation failed"
|
|
237
|
+
- Verify your app's origin is registered in `functions/config/domains.ts`
|
|
238
|
+
|
|
239
|
+
**Issue: "User info not loading after login" (Migration)**
|
|
240
|
+
- The hook automatically fetches user data if localStorage is empty (v2.0.4+)
|
|
241
|
+
- If migrating from old auth system, clear localStorage completely
|
|
242
|
+
- Ensure auth service `/user` endpoint is deployed (check Network tab)
|
|
243
|
+
- Verify refresh token cookie exists (Application → Cookies → `maven_refresh_token`)
|
|
244
|
+
- Check console for "Failed to fetch user data" - may indicate token/permission issue
|
|
245
|
+
|
|
229
246
|
## User Data Management
|
|
230
247
|
|
|
231
248
|
### Automatic User Data Fetching (v2.0.4+)
|
|
@@ -516,23 +533,124 @@ function App() {
|
|
|
516
533
|
export default App;
|
|
517
534
|
```
|
|
518
535
|
|
|
519
|
-
##
|
|
536
|
+
## Migrating Existing Apps to v2.0
|
|
537
|
+
|
|
538
|
+
### Quick Migration Checklist
|
|
539
|
+
|
|
540
|
+
If you're migrating an existing Maven app to use this centralized auth:
|
|
541
|
+
|
|
542
|
+
**1. Install Package**
|
|
543
|
+
```bash
|
|
544
|
+
npm install @mavenmm/teamwork-auth
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
**2. Add Environment Variables**
|
|
548
|
+
```bash
|
|
549
|
+
# For localhost development:
|
|
550
|
+
VITE_CLIENT_ID=<your_teamwork_client_id>
|
|
551
|
+
VITE_REDIRECT_URI=http://localhost:3000 # Match your dev port
|
|
552
|
+
VITE_DOMAIN_KEY=dev_localhost_shared
|
|
553
|
+
|
|
554
|
+
# For production (get from DevOps):
|
|
555
|
+
VITE_DOMAIN_KEY=<unique_production_key>
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
**3. Register Your Domain** (Production Only)
|
|
559
|
+
Contact DevOps to add your domain to `functions/config/domains.ts`:
|
|
560
|
+
- Production: `https://your-app.mavenmm.com`
|
|
561
|
+
- Staging: `https://your-app.netlify.app`
|
|
562
|
+
|
|
563
|
+
**4. Update Your App Code**
|
|
564
|
+
```tsx
|
|
565
|
+
import { useTeamworkAuth, Login } from '@mavenmm/teamwork-auth';
|
|
566
|
+
|
|
567
|
+
function App() {
|
|
568
|
+
const { user, isAuthenticated, loading, logout } = useTeamworkAuth();
|
|
569
|
+
|
|
570
|
+
if (loading) return <div>Loading...</div>;
|
|
571
|
+
|
|
572
|
+
if (!isAuthenticated) {
|
|
573
|
+
return <Login
|
|
574
|
+
clientID={import.meta.env.VITE_CLIENT_ID}
|
|
575
|
+
redirectURI={window.location.origin}
|
|
576
|
+
/>;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
return <div>Welcome {user?.firstName}! <button onClick={logout}>Logout</button></div>;
|
|
580
|
+
}
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
**5. Start Local Auth Service** (Development Only)
|
|
584
|
+
```bash
|
|
585
|
+
# Clone auth service repo
|
|
586
|
+
git clone <auth-service-repo>
|
|
587
|
+
cd <auth-service-repo>
|
|
520
588
|
|
|
521
|
-
|
|
589
|
+
# Set up .env with DEV_KEY=dev_localhost_shared
|
|
590
|
+
netlify dev --port 9100
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
**6. Test Authentication Flow**
|
|
594
|
+
- Clear browser cookies and localStorage
|
|
595
|
+
- Start your app (should auto-detect `localhost:9100`)
|
|
596
|
+
- Click login, authenticate with Teamwork
|
|
597
|
+
- Verify user data loads correctly
|
|
598
|
+
- Test logout and re-login
|
|
599
|
+
|
|
600
|
+
**7. Common Migration Issues**
|
|
601
|
+
|
|
602
|
+
| Problem | Solution |
|
|
603
|
+
|---------|----------|
|
|
604
|
+
| "Invalid domain key" | Use `dev_localhost_shared` for localhost, not port-specific keys |
|
|
605
|
+
| Cookies not persisting | Clear all cookies/localStorage and login fresh |
|
|
606
|
+
| User data is null | Hook auto-fetches from `/user` endpoint (v2.0.4+) - verify it's deployed |
|
|
607
|
+
| "Auth service unreachable" | Start local auth service on port 9100 |
|
|
608
|
+
| CORS errors | Verify your origin is in `functions/config/domains.ts` |
|
|
609
|
+
| 401 on Teamwork OAuth | Ensure `VITE_REDIRECT_URI` is registered in Teamwork OAuth app settings |
|
|
610
|
+
|
|
611
|
+
**8. Verify Production Deployment**
|
|
612
|
+
Before deploying to production:
|
|
613
|
+
- ✅ Domain registered in auth service
|
|
614
|
+
- ✅ `VITE_DOMAIN_KEY` env var set (production value)
|
|
615
|
+
- ✅ `VITE_CLIENT_ID` env var set
|
|
616
|
+
- ✅ `VITE_REDIRECT_URI` set to production URL
|
|
617
|
+
- ✅ Auth service `/user` endpoint deployed
|
|
618
|
+
- ✅ Test login/logout flow in staging first
|
|
619
|
+
|
|
620
|
+
### Migration from v1.x
|
|
621
|
+
|
|
622
|
+
If migrating from v1.x to v2.x:
|
|
522
623
|
|
|
523
624
|
1. **Update package:**
|
|
524
625
|
```bash
|
|
525
626
|
npm install @mavenmm/teamwork-auth@latest
|
|
526
627
|
```
|
|
527
628
|
|
|
528
|
-
2. **
|
|
629
|
+
2. **Add required environment variables:**
|
|
529
630
|
- Add `VITE_DOMAIN_KEY` (required in v2.0)
|
|
631
|
+
- For localhost: `dev_localhost_shared`
|
|
632
|
+
- For production: Get from DevOps
|
|
530
633
|
|
|
531
634
|
3. **Remove manual authServiceUrl config:**
|
|
532
|
-
- v2.0 auto-detects environment
|
|
635
|
+
- v2.0 auto-detects environment (localhost/production/staging)
|
|
636
|
+
- No need to manually specify auth service URL
|
|
533
637
|
|
|
534
|
-
4. **
|
|
638
|
+
4. **Clear old auth data:**
|
|
639
|
+
```tsx
|
|
640
|
+
// In your migration code or manually in browser console:
|
|
641
|
+
localStorage.clear();
|
|
642
|
+
// Also clear cookies in browser DevTools
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
5. **Update auth service:**
|
|
535
646
|
- Must use v2.0 auth service with domain authentication
|
|
647
|
+
- Contact DevOps to register your domain
|
|
648
|
+
|
|
649
|
+
6. **Test thoroughly:**
|
|
650
|
+
- Test localhost development flow
|
|
651
|
+
- Test staging deployment
|
|
652
|
+
- Test production deployment
|
|
653
|
+
- Verify user data persistence across page refreshes
|
|
536
654
|
|
|
537
655
|
See MIGRATION_V2.md in the auth service repo for detailed migration guide.
|
|
538
656
|
|
package/package.json
CHANGED