Separate login and display identities
This commit is contained in:
@@ -9,6 +9,7 @@ const SESSION_SECONDS = 60 * 60 * 24 * 30;
|
||||
export type AuthUser = {
|
||||
id: string;
|
||||
username: string;
|
||||
displayName: string;
|
||||
role: string;
|
||||
discordLinked: boolean;
|
||||
};
|
||||
@@ -55,11 +56,13 @@ export async function getSessionUser(cookies: Cookies): Promise<AuthUser | null>
|
||||
|
||||
const database = await getDatabase();
|
||||
const statement = await database.prepare(`
|
||||
SELECT users.id, users.username, users.role, users.discord_id,
|
||||
SELECT users.id, users.username, COALESCE(user_profiles.display_name,users.username) AS display_name,
|
||||
users.role, users.discord_id,
|
||||
user_status.last_active_at,user_status.blocked_at,user_status.banned_until,
|
||||
deleted_accounts.deleted_at
|
||||
FROM sessions
|
||||
JOIN users ON users.id = sessions.user_id
|
||||
LEFT JOIN user_profiles ON user_profiles.user_id=users.id
|
||||
LEFT JOIN user_status ON user_status.user_id=users.id
|
||||
LEFT JOIN deleted_accounts ON deleted_accounts.user_id=users.id
|
||||
WHERE sessions.token_hash = ? AND sessions.expires_at > ?
|
||||
@@ -86,6 +89,7 @@ export async function getSessionUser(cookies: Cookies): Promise<AuthUser | null>
|
||||
return {
|
||||
id: String(user.id),
|
||||
username: String(user.username),
|
||||
displayName: String(user.display_name),
|
||||
role: String(user.role),
|
||||
discordLinked: typeof user.discord_id === 'string'
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user