feat(auth): wire up refresh token endpoint and auto-refresh
- Add POST /api/refresh-token endpoint to router - Auth store now calls refreshTokenIfNeeded on init and every hour - Token refreshes automatically when within 2 weeks of expiry
This commit is contained in:
@@ -99,6 +99,8 @@ func main() {
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(mw.RequireAuth)
|
||||
|
||||
r.Post("/refresh-token", authHandlers.RefreshTokenHandler)
|
||||
|
||||
r.Get("/user/profile", user.GetProfileHandler)
|
||||
r.Put("/user/profile", user.UpdateProfileHandler)
|
||||
r.Delete("/user/account", user.DeleteAccountHandler)
|
||||
|
||||
@@ -32,6 +32,12 @@ class AuthStore {
|
||||
constructor() {
|
||||
if (browser) {
|
||||
this.initializeAuth();
|
||||
// Check token refresh every hour
|
||||
setInterval(() => {
|
||||
if (this.token) {
|
||||
this.refreshTokenIfNeeded();
|
||||
}
|
||||
}, 60 * 60 * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +76,8 @@ class AuthStore {
|
||||
lastName: ''
|
||||
};
|
||||
this.fetchUserProfile();
|
||||
// Check if token needs refresh
|
||||
this.refreshTokenIfNeeded();
|
||||
} else {
|
||||
this.clearAuth();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user