summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwikiapiserver2026-06-25 13:10:33 +0200
committerwikiapiserver2026-06-25 13:10:33 +0200
commit21fb3c12c86fe3f03531c4f323854da36fb82628 (patch)
tree24192f9b5b9b0226516e46bdd553317c5f0eb9a0
parent363d4edfed8361ba3121278eb5d7f5e5779e964c (diff)
downloadwikiapiserver-21fb3c12c86fe3f03531c4f323854da36fb82628.tar.gz
fix: update queries for new refresh_token_created column and add error logging
- INSERT and UPDATE now set both refresh_token_created and access_token_created timestamps - Register handler logs the actual error on failure
-rw-r--r--api/handlers.go2
-rw-r--r--db/db.go6
2 files changed, 5 insertions, 3 deletions
diff --git a/api/handlers.go b/api/handlers.go
index 0d23bdb..109eca3 100644
--- a/api/handlers.go
+++ b/api/handlers.go
@@ -3,6 +3,7 @@ package api
import (
"context"
"encoding/json"
+ "log"
"net/http"
"time"
@@ -84,6 +85,7 @@ func (h *Handler) Register(w http.ResponseWriter, r *http.Request) {
badRequest(w, "username already exists")
return
}
+ log.Printf("register error: %v", err)
serverError(w, "could not create account")
return
}
diff --git a/db/db.go b/db/db.go
index 50b1f17..059f1df 100644
--- a/db/db.go
+++ b/db/db.go
@@ -130,8 +130,8 @@ func (d *DB) CreateAccount(ctx context.Context, username, plaintextPW string) (*
}
res, err := d.conn.ExecContext(ctx,
- `INSERT INTO account (username, password, refresh_token, access_token, access_token_created)
- VALUES (?, ?, ?, ?, NOW())`,
+ `INSERT INTO account (username, password, refresh_token, access_token, refresh_token_created, access_token_created)
+ VALUES (?, ?, ?, ?, NOW(), NOW())`,
username, plaintextPW,
tokens.RefreshToken,
tokens.AccessToken,
@@ -199,7 +199,7 @@ func (d *DB) RotateTokens(ctx context.Context, id int64) (*Account, error) {
}
res, err := d.conn.ExecContext(ctx,
- `UPDATE account SET refresh_token = ?, access_token = ?, access_token_created = NOW()
+ `UPDATE account SET refresh_token = ?, access_token = ?, refresh_token_created = NOW(), access_token_created = NOW()
WHERE id = ?`, rt, at, id)
if err != nil {
return nil, fmt.Errorf("rotate tokens: %w", err)