handleLogout (api/auth_handler.go)

openilink-hub · internal/api/auth_handler.go · go · MIT
auth, tag:embed-classified

Provides HTTP handlers for user session logout, profile retrieval, and updates in an OpenILink hub.

// Source: https://github.com/openilink/openilink-hub | License: MIT | Copyright 2026 The OpeniLink Authors
// Provided via justclaw.it.com; keep this notice with the code.
package api

import (
	"encoding/json"
	"net/http"
	"strings"
	"time"

	"github.com/openilink/openilink-hub/internal/auth"
	"github.com/openilink/openilink-hub/internal/store"
)

// --- Session ---

func (s *Server) handleLogout(w http.ResponseWriter, r *http.Request) {
	if cookie, err := r.Cookie("session"); err == nil {
		auth.DeleteSession(s.Store, cookie.Value)
	}
	http.SetCookie(w, &http.Cookie{
		Name: "session", Value: "", Path: "/",
		HttpOnly: true, MaxAge: -1, Expires: time.Unix(0, 0),
	})
	jsonOK(w)
}

// --- Profile (authenticated) ---

func (s *Server) handleMe(w http.ResponseWriter, r *http.Request) {
	use

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key