Add switch user button and logout endpoint

This commit is contained in:
Ian Gulliver
2025-12-28 22:55:22 -08:00
parent 08b73725b1
commit 8ba3651415
2 changed files with 12 additions and 0 deletions

11
main.go
View File

@@ -23,6 +23,7 @@ func init() {
func main() {
http.HandleFunc("/", handleStatic)
http.HandleFunc("/auth/google/callback", handleGoogleCallback)
http.HandleFunc("/auth/logout", handleLogout)
log.Println("server starting on :8080")
log.Fatal(http.ListenAndServe(":8080", nil))
@@ -99,6 +100,16 @@ func setProfile(w http.ResponseWriter, profile map[string]any) {
})
}
func handleLogout(w http.ResponseWriter, r *http.Request) {
http.SetCookie(w, &http.Cookie{
Name: "profile",
Value: "",
Path: "/",
MaxAge: -1,
})
http.Redirect(w, r, "/", http.StatusSeeOther)
}
func handleGoogleCallback(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)

View File

@@ -38,6 +38,7 @@
</div>
</div>
<p>Welcome to HCA Tickets!</p>
<wa-button variant="neutral" href="/auth/logout">Switch User</wa-button>
</wa-card>
<script type="module">
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {