forked from FoundKeyGang/FoundKey
improve authentication errors
This commit is contained in:
parent
91bdab1a9d
commit
edac21e8f7
2 changed files with 9 additions and 5 deletions
|
@ -47,11 +47,15 @@ export default (endpoint: IEndpoint, ctx: Koa.Context) => new Promise<void>((res
|
||||||
});
|
});
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
if (e instanceof AuthenticationError) {
|
if (e instanceof AuthenticationError) {
|
||||||
reply(403, new ApiError({
|
ctx.response.status = 403;
|
||||||
message: 'Authentication failed. Please ensure your token is correct.',
|
ctx.response.set('WWW-Authenticate', 'Bearer');
|
||||||
|
ctx.response.body = {
|
||||||
|
message: 'Authentication failed: ' + e.message,
|
||||||
code: 'AUTHENTICATION_FAILED',
|
code: 'AUTHENTICATION_FAILED',
|
||||||
id: 'b0a7f5f8-dc2f-4171-b91f-de88ad238e14',
|
id: 'b0a7f5f8-dc2f-4171-b91f-de88ad238e14',
|
||||||
}));
|
kind: 'client',
|
||||||
|
};
|
||||||
|
res();
|
||||||
} else {
|
} else {
|
||||||
reply(500, new ApiError());
|
reply(500, new ApiError());
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ export default async (authorization: string | null | undefined, bodyToken: strin
|
||||||
() => Users.findOneBy({ token }) as Promise<ILocalUser | null>);
|
() => Users.findOneBy({ token }) as Promise<ILocalUser | null>);
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new AuthenticationError('user not found');
|
throw new AuthenticationError('unknown token');
|
||||||
}
|
}
|
||||||
|
|
||||||
return [user, null];
|
return [user, null];
|
||||||
|
@ -56,7 +56,7 @@ export default async (authorization: string | null | undefined, bodyToken: strin
|
||||||
});
|
});
|
||||||
|
|
||||||
if (accessToken == null) {
|
if (accessToken == null) {
|
||||||
throw new AuthenticationError('invalid signature');
|
throw new AuthenticationError('unknown token');
|
||||||
}
|
}
|
||||||
|
|
||||||
AccessTokens.update(accessToken.id, {
|
AccessTokens.update(accessToken.id, {
|
||||||
|
|
Loading…
Reference in a new issue