Add switch user button and logout endpoint
This commit is contained in:
11
main.go
11
main.go
@@ -23,6 +23,7 @@ func init() {
|
|||||||
func main() {
|
func main() {
|
||||||
http.HandleFunc("/", handleStatic)
|
http.HandleFunc("/", handleStatic)
|
||||||
http.HandleFunc("/auth/google/callback", handleGoogleCallback)
|
http.HandleFunc("/auth/google/callback", handleGoogleCallback)
|
||||||
|
http.HandleFunc("/auth/logout", handleLogout)
|
||||||
|
|
||||||
log.Println("server starting on :8080")
|
log.Println("server starting on :8080")
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
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) {
|
func handleGoogleCallback(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p>Welcome to HCA Tickets!</p>
|
<p>Welcome to HCA Tickets!</p>
|
||||||
|
<wa-button variant="neutral" href="/auth/logout">Switch User</wa-button>
|
||||||
</wa-card>
|
</wa-card>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
|
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
|
||||||
|
|||||||
Reference in New Issue
Block a user