Files
website/internal/auth/handlers.go
2025-10-28 13:36:05 +11:00

26 lines
712 B
Go

package auth
import (
"net/http"
ory "github.com/ory/client-go"
)
func LoginHandler(oryClient *ory.APIClient, tunnelURL string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, tunnelURL+"/ui/login", http.StatusSeeOther)
}
}
func LogOutHandler(oryClient *ory.APIClient, tunnelURL string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cookies := r.Header.Get("Cookie")
logoutFlow, _, err := oryClient.FrontendAPI.CreateBrowserLogoutFlow(r.Context()).Cookie(cookies).Execute()
if err != nil {
http.Redirect(w, r, "/", http.StatusSeeOther)
return
}
http.Redirect(w, r, logoutFlow.LogoutUrl, http.StatusSeeOther)
}
}