Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: improve and extend auth middleware #26

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func (a *API) authenticator(next http.Handler) http.Handler {
ErrGenericInternalServerError.Withf("could not retrieve user from database: %v", err).Write(w)
return
}
// check if the user is already verified
if !user.Verified {
ErrUserNoVerified.With("user account not verified").Write(w)
return
}
// add the user to the context
ctx := context.WithValue(r.Context(), userMetadataKey, *user)
// token is authenticated, pass it through with the new context with the
Expand Down
10 changes: 0 additions & 10 deletions api/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,6 @@ func (a *API) inviteOrganizationMemberHandler(w http.ResponseWriter, r *http.Req
ErrUnauthorized.Withf("user is not admin of organization").Write(w)
return
}
// check if the user is already verified
if !user.Verified {
ErrUserNoVerified.With("user account not verified").Write(w)
return
}
// get new admin info from the request body
invite := &OrganizationInvite{}
if err := json.NewDecoder(r.Body).Decode(invite); err != nil {
Expand Down Expand Up @@ -414,11 +409,6 @@ func (a *API) pendingOrganizationMembersHandler(w http.ResponseWriter, r *http.R
ErrUnauthorized.Withf("user is not admin of organization").Write(w)
return
}
// check if the user is already verified
if !user.Verified {
ErrUserNoVerified.With("user account not verified").Write(w)
return
}
// get the pending invitations
invitations, err := a.db.PendingInvitations(org.Address)
if err != nil {
Expand Down
Loading