Add user authentication and game persistence with SQLite
- User registration/login with bcrypt password hashing - SQLite database with goose migrations and sqlc-generated queries - Games and players persisted to database, resumable after restart - Guest play still supported alongside authenticated users - Auth UI components (login/register forms, auth header, guest banner)
This commit is contained in:
31
db/queries/games.sql
Normal file
31
db/queries/games.sql
Normal file
@@ -0,0 +1,31 @@
|
||||
-- name: CreateGame :one
|
||||
INSERT INTO games (id, board, current_turn, status)
|
||||
VALUES (?, ?, ?, ?)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetGame :one
|
||||
SELECT * FROM games WHERE id = ?;
|
||||
|
||||
-- name: UpdateGame :exec
|
||||
UPDATE games
|
||||
SET board = ?, current_turn = ?, status = ?, winner_user_id = ?, winning_cells = ?, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = ?;
|
||||
|
||||
-- name: DeleteGame :exec
|
||||
DELETE FROM games WHERE id = ?;
|
||||
|
||||
-- name: GetActiveGames :many
|
||||
SELECT * FROM games WHERE status < 2;
|
||||
|
||||
-- name: CreateGamePlayer :exec
|
||||
INSERT INTO game_players (game_id, user_id, guest_player_id, nickname, color, slot)
|
||||
VALUES (?, ?, ?, ?, ?, ?);
|
||||
|
||||
-- name: GetGamePlayers :many
|
||||
SELECT * FROM game_players WHERE game_id = ?;
|
||||
|
||||
-- name: GetGamesByUserID :many
|
||||
SELECT g.* FROM games g
|
||||
JOIN game_players gp ON g.id = gp.game_id
|
||||
WHERE gp.user_id = ?
|
||||
ORDER BY g.updated_at DESC;
|
||||
10
db/queries/users.sql
Normal file
10
db/queries/users.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
-- name: CreateUser :one
|
||||
INSERT INTO users (id, username, password_hash)
|
||||
VALUES (?, ?, ?)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetUserByID :one
|
||||
SELECT * FROM users WHERE id = ?;
|
||||
|
||||
-- name: GetUserByUsername :one
|
||||
SELECT * FROM users WHERE username = ?;
|
||||
Reference in New Issue
Block a user