8000 feat: delete API token in /logout API by AbhineetJain · Pull Request #1770 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: delete API token in /logout API #1770

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

Merged
merged 19 commits into from
May 27, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
delete api key in logout inline
  • Loading branch information
AbhineetJain committed May 26, 2022
commit 994a29477e0c9cf98b32033921fa6fa04f70576e
24 changes: 8 additions & 16 deletions coderd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,14 @@ func (api *API) postAPIKey(rw http.ResponseWriter, r *http.Request) {
}

// Clear the user's session cookie
func (api *api) postLogout(rw http.ResponseWriter, r *http.Request) {
func (api *API) postLogout(rw http.ResponseWriter, r *http.Request) {
// Delete the session token from database
ok := api.deleteAPIKey(rw, r)
if !ok {
apiKey := httpmw.APIKey(r)
err := api.Database.DeleteAPIKeyByID(r.Context(), apiKey.ID)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: fmt.Sprintf("delete api key: %s", err.Error()),
})
return
}

Expand Down Expand Up @@ -749,19 +753,7 @@ func (api *API) createAPIKey(rw http.ResponseWriter, r *http.Request, params dat
return sessionToken, true
}

func (api *api) deleteAPIKey(rw http.ResponseWriter, r *http.Request) bool {
apiKey := httpmw.APIKey(r)
err := api.Database.DeleteAPIKeyByID(r.Context(), apiKey.ID)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: fmt.Sprintf("delete api key: %s", err.Error()),
})
return false
}
return true
}

func (api *api) createUser(ctx context.Context, req codersdk.CreateUserRequest) (database.User, uuid.UUID, error) {
func (api *API) createUser(ctx context.Context, req codersdk.CreateUserRequest) (database.User, uuid.UUID, error) {
var user database.User
return user, req.OrganizationID, api.Database.InTx(func(db database.Store) error {
var orgRoles []string
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0