Add CORS support for user profile and account routes in the API
This commit is contained in:
@@ -102,7 +102,9 @@ class _AccountSettingsDialogState extends State<AccountSettingsDialog> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _updateProfile() async {
|
Future<void> _updateProfile() async {
|
||||||
if (_currentUser == null) return;
|
if (_currentUser == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setState(() => _isLoading = true);
|
setState(() => _isLoading = true);
|
||||||
try {
|
try {
|
||||||
|
|||||||
BIN
go_cloud/bin/api
BIN
go_cloud/bin/api
Binary file not shown.
@@ -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) {
|
r.Put("/user/profile", func(w http.ResponseWriter, req *http.Request) {
|
||||||
updateUserProfileHandler(w, req, db, auditLogger)
|
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) {
|
r.Post("/user/change-password", func(w http.ResponseWriter, req *http.Request) {
|
||||||
changePasswordHandler(w, req, db, auditLogger)
|
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) {
|
r.Post("/user/avatar", func(w http.ResponseWriter, req *http.Request) {
|
||||||
uploadUserAvatarHandler(w, req, db, auditLogger, cfg)
|
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) {
|
r.Delete("/user/account", func(w http.ResponseWriter, req *http.Request) {
|
||||||
deleteUserAccountHandler(w, req, db, auditLogger, cfg)
|
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
|
// Org routes
|
||||||
r.Get("/orgs", func(w http.ResponseWriter, req *http.Request) {
|
r.Get("/orgs", func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user