diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2021-07-18 00:53:16 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-18 00:53:16 +0900 |
| commit | 62dede02eaf93a6ca08983bbf84a8a71e67fa6eb (patch) | |
| tree | f11dcacfa99b93c8f1d88bcd622e59499939cdb9 /src/server/api/authenticate.ts | |
| parent | Improve type (diff) | |
| download | sharkey-62dede02eaf93a6ca08983bbf84a8a71e67fa6eb.tar.gz sharkey-62dede02eaf93a6ca08983bbf84a8a71e67fa6eb.tar.bz2 sharkey-62dede02eaf93a6ca08983bbf84a8a71e67fa6eb.zip | |
API AuthenticateでDB接続エラーなどが発生するとログアウトさせられてしまうのを修正 Fix #7603 (#7604)
Diffstat (limited to 'src/server/api/authenticate.ts')
| -rw-r--r-- | src/server/api/authenticate.ts | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/server/api/authenticate.ts b/src/server/api/authenticate.ts index 6ea5a111bc..bba4db4ace 100644 --- a/src/server/api/authenticate.ts +++ b/src/server/api/authenticate.ts @@ -8,7 +8,14 @@ import { Cache } from '@/misc/cache'; // ref. https://github.com/typeorm/typeorm/blob/master/docs/caching.md const cache = new Cache<User>(1000 * 60 * 60); -export default async (token: string): Promise<[User | null | undefined, AccessToken | null | undefined]> => { +export class AuthenticationError extends Error { + constructor(message: string) { + super(message); + this.name = 'AuthenticationError'; + } +} + +export default async (token: string): Promise<[User | null | undefined, App | null | undefined]> => { if (token == null) { return [null, null]; } @@ -24,7 +31,7 @@ export default async (token: string): Promise<[User | null | undefined, AccessTo .findOne({ token }); if (user == null) { - throw new Error('user not found'); + throw new AuthenticationError('user not found'); } cache.set(token, user); @@ -41,7 +48,7 @@ export default async (token: string): Promise<[User | null | undefined, AccessTo }); if (accessToken == null) { - throw new Error('invalid signature'); + throw new AuthenticationError('invalid signature'); } AccessTokens.update(accessToken.id, { |