You're getting "Not authorized to access this route" when trying to post a gig.
The backend API requires authentication, but one of these is happening:
- You're not logged in
- Your login token expired
- The token isn't being sent correctly
- Click your profile/avatar in the top right
- Click "Logout"
- Login again with your credentials
- Try posting a gig again
This will refresh your authentication token.
Open browser console (F12) and type:
localStorage.getItem('token')- If it returns
null→ You're NOT logged in - If it returns a long string → You ARE logged in
- Open DevTools (F12)
- Go to Network tab
- Try posting a gig
- Click on the
/gigsrequest - Go to Headers tab
- Look for
Authorization: Bearer <token>
If you don't see the Authorization header, that's the problem.
The error "Not authorized to access this route" comes from the backend when:
- No
Authorizationheader is present - The token is invalid or expired
- The token doesn't match any user in the database
I've improved the error handling to show you the exact error message. Now when you try to post a gig, you'll see the specific error.
You need to login again:
- Logout
- Login with valid credentials
- Try posting again
Your session expired:
- Logout
- Login again
- Try posting again
Share the exact error message with me and I'll help fix it.
- Look for your name/avatar in the top right
- If not there, you're not logged in
- Click "Login" or "Sign Up"
- Enter your credentials
- Make sure you see "Login successful" or similar message
- Your name should appear in the top right
- Click "Post a Gig" button
- Fill in all fields
- Click "Post Gig"
- If you get an error, note the exact message
If you just signed up:
- ✅ You should be automatically logged in
- ✅ Token should be saved
- ✅ Posting should work
If you're coming back after some time:
⚠️ Your token might have expired- 🔧 Solution: Logout and login again
If you logged out in another tab:
⚠️ Token is removed from all tabs- 🔧 Solution: Login again in this tab
- User logs in → Backend generates JWT token
- Frontend saves token in
localStorage - Every API request includes:
Authorization: Bearer <token> - Backend verifies token and allows/denies access
- Tokens expire after 7 days (configured in backend)
- After expiration, you must login again
- No automatic refresh (for security)
Frontend (PostGig)
↓
gigService.createGig(data)
↓
axios adds: Authorization: Bearer <token>
↓
POST /api/gigs
↓
Backend checks token
↓
If valid: Create gig ✅
If invalid: "Not authorized" ❌
I've improved the error handling and pushed the changes. Wait 2-3 minutes for Vercel to deploy, then:
- Hard refresh:
Ctrl + Shift + R - Logout and login again
- Try posting a gig
- You should see a more specific error message if it fails
Try this now:
- Logout from your account
- Login again
- Try posting a gig
- If it still fails, share the exact error message you see
The improved error handling will tell us exactly what's wrong!
Most likely solution: Just logout and login again! 🔄