Skip to content

Commit 16a7e57

Browse files
committed
Initial logout route
1 parent c6035aa commit 16a7e57

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

coderd/coderd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func New(options *Options) http.Handler {
3333
})
3434
r.Post("/user", users.createInitialUser)
3535
r.Post("/login", users.loginWithPassword)
36+
r.Post("/logout", logout)
3637
// Require an API key and authenticated user for this group.
3738
r.Group(func(r chi.Router) {
3839
r.Use(

coderd/users.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,21 @@ func (users *users) loginWithPassword(rw http.ResponseWriter, r *http.Request) {
199199
})
200200
}
201201

202+
// Clear the user's session cookie
203+
func logout(rw http.ResponseWriter, r *http.Request) {
204+
// Get a blank token cookie
205+
cookie := &http.Cookie{
206+
// MaxAge < 0 means to delete the cookie now
207+
MaxAge: -1,
208+
Name: httpmw.AuthCookie,
209+
Path: "/",
210+
}
211+
212+
http.SetCookie(rw, cookie)
213+
214+
render.Status(r, http.StatusOK)
215+
}
216+
202217
// Generates a new ID and secret for an API key.
203218
func generateAPIKeyIDSecret() (id string, secret string, err error) {
204219
// Length of an API Key ID.

0 commit comments

Comments
 (0)