mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-21 21:36:26 -08:00
token-permissions: bugfix
This commit is contained in:
parent
8bec8a4360
commit
5e15b20c10
|
@ -59,16 +59,20 @@ export function tokenFor(req: express.Request) {
|
|||
)
|
||||
}
|
||||
|
||||
function getToken(token:string) {
|
||||
return AuthTokens.find(e => e.token == token && Date.now() < e.expire)
|
||||
}
|
||||
|
||||
export function validate(token:string) {
|
||||
return AuthTokens.find(e => e.token == token && Date.now() < e.expire)?.account
|
||||
return getToken(token)?.account
|
||||
}
|
||||
|
||||
export function getType(token:string): TokenType | undefined {
|
||||
return AuthTokens.find(e => e.token == token && Date.now() < e.expire)?.type
|
||||
return getToken(token)?.type
|
||||
}
|
||||
|
||||
export function getPermissions(token:string): TokenPermission[] | undefined {
|
||||
return AuthTokens.find(e => e.token == token && Date.now() < e.expire)?.tokenPermissions
|
||||
return getToken(token)?.tokenPermissions
|
||||
}
|
||||
|
||||
export function tokenTimer(token:AuthToken) {
|
||||
|
|
|
@ -41,12 +41,12 @@ export const requiresPermissions = function(...tokenPermissions: auth.TokenPermi
|
|||
if (!permissions) ServeError(res, 403, "insufficient permissions")
|
||||
else {
|
||||
|
||||
for (let v in tokenPermissions)
|
||||
for (let v of tokenPermissions) {
|
||||
if (!permissions.includes(v as auth.TokenPermission)) {
|
||||
ServeError(res,403,"insufficient permissions")
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
next()
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue