Add sign out button
This commit is contained in:
@@ -92,6 +92,26 @@ func (u Users) PostSignin(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "User authenticated: %+v", user)
|
||||
}
|
||||
|
||||
func (u Users) GetSignout(w http.ResponseWriter, r *http.Request) {
|
||||
sessionCookie, err := r.Cookie("session")
|
||||
if err != nil {
|
||||
http.Redirect(w, r, "/signin", http.StatusFound)
|
||||
return
|
||||
}
|
||||
err = u.SessionService.Delete(sessionCookie.Value)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
c := http.Cookie{
|
||||
Name: "session",
|
||||
MaxAge: -1,
|
||||
}
|
||||
http.SetCookie(w, &c)
|
||||
http.Redirect(w, r, "/signin", http.StatusFound)
|
||||
}
|
||||
|
||||
func (u Users) CurrentUser(w http.ResponseWriter, r *http.Request) {
|
||||
seshCookie, err := r.Cookie("session")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user