fix: adminOnly checks isAdmin flag from stored tokens
This commit is contained in:
@@ -36,7 +36,7 @@ export async function authMiddleware(req, res, next) {
|
|||||||
|
|
||||||
req.token = token;
|
req.token = token;
|
||||||
req.tokenLabel = validToken.label;
|
req.tokenLabel = validToken.label;
|
||||||
req.isAdmin = token === config.adminToken;
|
req.isAdmin = validToken.isAdmin === true || token === config.adminToken;
|
||||||
next();
|
next();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof UnauthorizedError) {
|
if (err instanceof UnauthorizedError) {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ router.post('/token', authMiddleware, adminOnly, async (req, res) => {
|
|||||||
const token = `snk_${generateId().replace(/-/g, '')}`;
|
const token = `snk_${generateId().replace(/-/g, '')}`;
|
||||||
const now = new Date().toISOString();
|
const now = new Date().toISOString();
|
||||||
|
|
||||||
tokens.tokens.push({ token, label, createdAt: now });
|
tokens.tokens.push({ token, label, isAdmin: true, createdAt: now });
|
||||||
writeTokens(tokens);
|
writeTokens(tokens);
|
||||||
|
|
||||||
res.status(201).json({ token, label, createdAt: now });
|
res.status(201).json({ token, label, createdAt: now });
|
||||||
|
|||||||
Reference in New Issue
Block a user