siga

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit ce0e258f6c4a4d7bd4a8c35cf6f62ed61f7d4e58
parent 399a2cdcb0dd397be186ba710001df3b6e03204c
Author: Gabriel G. de Brito <me@gboncoffee.dev.br>
Date:   Sun,  8 Nov 2026 20:44:49 -0300

Authentication works.

Diffstat:
Aauth/authenticated.go | 25+++++++++++++++++++++++++
Mauth/repository/repository.go | 6+++---
Mauth/router.go | 2+-
3 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/auth/authenticated.go b/auth/authenticated.go @@ -0,0 +1,25 @@ +package main + +import ( + "log" + "net/http" + "uuid" + + "github.com/gboncoffee/siga/auth/repository" +) + +func authenticated(w http.ResponseWriter, r *http.Request) { + token, err := uuid.Parse(r.PathValue("uuid")) + if err != nil { + http.Error(w, "invalid token", http.StatusUnauthorized) + return + } + if err := repository.SessionExists(token); err != nil { + log.Println(err) + http.Error(w, "invalid token", http.StatusUnauthorized) + return + } + + w.WriteHeader(http.StatusOK) + return +} diff --git a/auth/repository/repository.go b/auth/repository/repository.go @@ -68,11 +68,11 @@ func NewSession(token uuid.UUID) error { return err } -func SessionExists(token uuid.UUID) bool { +func SessionExists(token uuid.UUID) error { var t uuid.UUID err := db.QueryRow( `SELECT token FROM sessions WHERE token = ?`, - token, + token[:], ).Scan(&t) - return err == nil + return err } diff --git a/auth/router.go b/auth/router.go @@ -6,5 +6,5 @@ func router() { http.HandleFunc("POST /login", login) // http.HandleFunc("POST /logout", logout) http.HandleFunc("POST /credentials", credentials) - // http.HandleFunc("GET /{uuid}", authenticated) + http.HandleFunc("GET /{uuid}", authenticated) }