添加退出登录按钮
This commit is contained in:
22
server.js
22
server.js
@@ -195,6 +195,16 @@ const createValkeySession = async (res, credentials) => {
|
||||
return sessionId;
|
||||
};
|
||||
|
||||
const destroyValkeySession = async (req, res) => {
|
||||
const cookies = parseCookieHeader(req.headers.cookie || '');
|
||||
const sessionId = cookies[SESSION_COOKIE_NAME];
|
||||
if (sessionId && valkeyEnabled && valkeyClient) {
|
||||
await valkeyClient.del(getSessionStorageKey(sessionId));
|
||||
console.log(`[auth] session cleared sessionId=${sessionId}`);
|
||||
}
|
||||
clearSessionCookie(res);
|
||||
};
|
||||
|
||||
const loadValkeySession = async (req) => {
|
||||
if (!valkeyEnabled || !valkeyClient) {
|
||||
return null;
|
||||
@@ -602,7 +612,7 @@ app.get('/api/buckets', async (req, res) => {
|
||||
await createValkeySession(res, auth);
|
||||
}
|
||||
console.log(`[s3] list buckets complete count=${buckets.length}`);
|
||||
res.json({ buckets });
|
||||
res.json({ buckets, username: auth.username || '' });
|
||||
} catch (error) {
|
||||
if (auth?.source === 'session') {
|
||||
clearSessionCookie(res);
|
||||
@@ -612,6 +622,16 @@ app.get('/api/buckets', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/logout', async (req, res) => {
|
||||
try {
|
||||
await destroyValkeySession(req, res);
|
||||
res.json({ ok: true });
|
||||
} catch (error) {
|
||||
console.error('[auth] logout failed:', error);
|
||||
res.status(500).json({ error: 'Failed to logout', detail: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Endpoint to list videos in the bucket
|
||||
app.get('/api/videos', async (req, res) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user