diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-07-20 12:11:07 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-07-20 12:11:07 +0900 |
| commit | acb92442058fa2458967425efb7324ab0646a335 (patch) | |
| tree | afc2ac62a7bbddce5756fc49f1caba9f7cba5407 /src/server/api/authenticate.ts | |
| parent | Merge branch 'develop' (diff) | |
| parent | 12.84.0 (diff) | |
| download | misskey-acb92442058fa2458967425efb7324ab0646a335.tar.gz misskey-acb92442058fa2458967425efb7324ab0646a335.tar.bz2 misskey-acb92442058fa2458967425efb7324ab0646a335.zip | |
Merge branch 'develop'
Diffstat (limited to 'src/server/api/authenticate.ts')
| -rw-r--r-- | src/server/api/authenticate.ts | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/server/api/authenticate.ts b/src/server/api/authenticate.ts index 6ea5a111bc..6148ad33c5 100644 --- a/src/server/api/authenticate.ts +++ b/src/server/api/authenticate.ts @@ -2,36 +2,30 @@ import isNativeToken from './common/is-native-token'; import { User } from '../../models/entities/user'; import { Users, AccessTokens, Apps } from '../../models'; import { AccessToken } from '../../models/entities/access-token'; -import { Cache } from '@/misc/cache'; -// TODO: TypeORMのカスタムキャッシュプロバイダを使っても良いかも -// ref. https://github.com/typeorm/typeorm/blob/master/docs/caching.md -const cache = new Cache<User>(1000 * 60 * 60); +export class AuthenticationError extends Error { + constructor(message: string) { + super(message); + this.name = 'AuthenticationError'; + } +} -export default async (token: string): Promise<[User | null | undefined, AccessToken | null | undefined]> => { +export default async (token: string): Promise<[User | null | undefined, App | null | undefined]> => { if (token == null) { return [null, null]; } if (isNativeToken(token)) { - const cached = cache.get(token); - if (cached) { - return [cached, null]; - } - // Fetch user const user = await Users .findOne({ token }); if (user == null) { - throw new Error('user not found'); + throw new AuthenticationError('user not found'); } - cache.set(token, user); - return [user, null]; } else { - // TODO: cache const accessToken = await AccessTokens.findOne({ where: [{ hash: token.toLowerCase() // app @@ -41,7 +35,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, { |