refacto: Deleting email mentions as there's no emailing system
This commit is contained in:
@@ -7,7 +7,6 @@ export async function initUsersSchema() {
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
password_hash TEXT NOT NULL,
|
||||
team TEXT NOT NULL CHECK (team IN ('blue', 'red')),
|
||||
role TEXT NOT NULL DEFAULT 'user' CHECK (role IN ('user', 'admin')),
|
||||
@@ -18,19 +17,19 @@ export async function initUsersSchema() {
|
||||
|
||||
// ── Queries ───────────────────────────────────────────────────────────────────
|
||||
|
||||
export async function createUser(username, email, passwordHash, team) {
|
||||
export async function createUser(username, passwordHash, team) {
|
||||
const { rows } = await usersPool.query(
|
||||
`INSERT INTO users (username, email, password_hash, team)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, username, email, team, role`,
|
||||
[username, email, passwordHash, team]
|
||||
`INSERT INTO users (username, password_hash, team)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING id, username, team, role`,
|
||||
[username, passwordHash, team]
|
||||
);
|
||||
return rows[0];
|
||||
}
|
||||
|
||||
export async function getUserByUsername(username) {
|
||||
const { rows } = await usersPool.query(
|
||||
`SELECT id, username, email, team, role, password_hash FROM users WHERE username = $1`,
|
||||
`SELECT id, username, team, role, password_hash FROM users WHERE username = $1`,
|
||||
[username]
|
||||
);
|
||||
return rows[0] ?? null;
|
||||
@@ -38,7 +37,7 @@ export async function getUserByUsername(username) {
|
||||
|
||||
export async function getUserById(id) {
|
||||
const { rows } = await usersPool.query(
|
||||
`SELECT id, username, email, team, role FROM users WHERE id = $1`,
|
||||
`SELECT id, username, team, role FROM users WHERE id = $1`,
|
||||
[id]
|
||||
);
|
||||
return rows[0] ?? null;
|
||||
|
||||
@@ -16,8 +16,8 @@ function issueToken(user) {
|
||||
|
||||
// POST /api/auth/register
|
||||
router.post("/register", async (req, res) => {
|
||||
const { username, email, password, team } = req.body ?? {};
|
||||
if (!username || !email || !password || !team) {
|
||||
const { username, password, team } = req.body ?? {};
|
||||
if (!username || !password || !team) {
|
||||
return res.status(400).json({ error: "missing_fields" });
|
||||
}
|
||||
if (team !== "blue" && team !== "red") {
|
||||
@@ -31,7 +31,7 @@ router.post("/register", async (req, res) => {
|
||||
}
|
||||
try {
|
||||
const passwordHash = await bcrypt.hash(password, 12);
|
||||
const user = await createUser(username.trim(), email.trim().toLowerCase(), passwordHash, team);
|
||||
const user = await createUser(username.trim(), passwordHash, team);
|
||||
const token = issueToken(user);
|
||||
return res.status(201).json({
|
||||
token,
|
||||
@@ -39,7 +39,6 @@ router.post("/register", async (req, res) => {
|
||||
});
|
||||
} catch (e) {
|
||||
if (e.code === "23505") {
|
||||
if (e.constraint?.includes("email")) return res.status(409).json({ error: "email_taken" });
|
||||
return res.status(409).json({ error: "username_taken" });
|
||||
}
|
||||
console.error(e);
|
||||
|
||||
Reference in New Issue
Block a user