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:
2026-02-17 21:54:45 +00:00
parent e20263b717
commit 1082631525
2 changed files with 10 additions and 0 deletions
+2
View File
@@ -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)
+8
View File
@@ -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();
}