Skip to content

Commit

Permalink
Merge pull request #97 from atnomoverflow/feat/atnomoverflow/handle-n…
Browse files Browse the repository at this point in the history
…ew-user-error

added 404 if the user not in database
  • Loading branch information
MarekCounts authored Mar 22, 2024
2 parents 4c4d833 + 0788049 commit 7b99e04
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions api/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ var (
UnauthorizedErrorHandler = func(w http.ResponseWriter) {
writeError(w, "Unauthorized", http.StatusUnauthorized)
}
UserRegistrationError = func(w http.ResponseWriter) {
writeError(w, "User not found in the database. Please complete the registration process.", http.StatusNotFound)
}
)
4 changes: 3 additions & 1 deletion api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ func main() {
})

c := cors.New(cors.Options{
AllowedOrigins: []string{"http://localhost:9000", "*"},
AllowedOrigins: []string{"http://localhost:9000", "http://localhost:5173", "*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowedHeaders: []string{"Content-Type", "Authorization"},
AllowCredentials: true,
})

Expand Down
7 changes: 5 additions & 2 deletions api/middleware/dumbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ func (k *AuthzMiddleware) CheckAuthz(next http.Handler) http.Handler {
_, err := user.GetUserForId(userId, k.db)

if err != nil {
http.Error(w, "User is new, please register user", http.StatusBadRequest)
w.Header().Set("location", "/newuser")
// http.Error(w, "User is new, please register user", http.StatusBadRequest)
// w.Header().Set("location", "/newuser")
core.UserRegistrationError(w)
fmt.Println("The front handle new user sign up")

return
}
org, err := user.GetOrgByOwnerId(userId, k.db)
Expand Down
2 changes: 1 addition & 1 deletion api/users/controllers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func resourceGroupModelToProto(resourceGroups []*models.ResourceGroup) []*pb.Res

func (u *UserController) AddAllControllers(router *mux.Router) {
router.HandleFunc("", u.UpsertUser).Methods("POST")
router.HandleFunc("/id", u.GetUserId).Methods("GET")
router.HandleFunc("", u.GetUserId).Methods("GET")
}

func (u *UserController) UpsertUserDB(user models.User) (int, error) {
Expand Down

0 comments on commit 7b99e04

Please sign in to comment.