Add CORS support for user profile and account routes in the API

This commit is contained in:
Leon Bösche
2026-01-29 00:59:22 +01:00
parent fcfcc3e127
commit b6a9e2aa54
3 changed files with 27 additions and 1 deletions

View File

@@ -102,7 +102,9 @@ class _AccountSettingsDialogState extends State<AccountSettingsDialog> {
}
Future<void> _updateProfile() async {
if (_currentUser == null) return;
if (_currentUser == null) {
return;
}
setState(() => _isLoading = true);
try {

Binary file not shown.

View File

@@ -241,15 +241,39 @@ func NewRouter(cfg *config.Config, db *database.DB, jwtManager *jwt.Manager, aut
r.Put("/user/profile", func(w http.ResponseWriter, req *http.Request) {
updateUserProfileHandler(w, req, db, auditLogger)
})
r.Options("/user/profile", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, PUT, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
w.WriteHeader(http.StatusOK)
})
r.Post("/user/change-password", func(w http.ResponseWriter, req *http.Request) {
changePasswordHandler(w, req, db, auditLogger)
})
r.Options("/user/change-password", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
w.WriteHeader(http.StatusOK)
})
r.Post("/user/avatar", func(w http.ResponseWriter, req *http.Request) {
uploadUserAvatarHandler(w, req, db, auditLogger, cfg)
})
r.Options("/user/avatar", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
w.WriteHeader(http.StatusOK)
})
r.Delete("/user/account", func(w http.ResponseWriter, req *http.Request) {
deleteUserAccountHandler(w, req, db, auditLogger, cfg)
})
r.Options("/user/account", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "DELETE, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
w.WriteHeader(http.StatusOK)
})
// Org routes
r.Get("/orgs", func(w http.ResponseWriter, req *http.Request) {