This commit is contained in:
tamaina 2023-06-04 16:41:45 +00:00
parent f651ca4b48
commit 35b1f73b51
9 changed files with 149 additions and 151 deletions

View file

@ -5,61 +5,10 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { DI } from '@/di-symbols.js';
import { ApiError } from '../../../error.js';
export const meta = {
tags: ['auth'],
requireCredential: false,
res: {
type: 'object',
optional: false, nullable: false,
properties: {
accessToken: {
type: 'string',
optional: false, nullable: false,
},
user: {
type: 'object',
optional: false, nullable: false,
ref: 'UserDetailedNotMe',
},
},
},
errors: {
noSuchApp: {
message: 'No such app.',
code: 'NO_SUCH_APP',
id: 'fcab192a-2c5a-43b7-8ad8-9b7054d8d40d',
},
noSuchSession: {
message: 'No such session.',
code: 'NO_SUCH_SESSION',
id: '5b5a1503-8bc8-4bd0-8054-dc189e8cdcb3',
},
pendingSession: {
message: 'This session is not completed yet.',
code: 'PENDING_SESSION',
id: '8c8a4145-02cc-4cca-8e66-29ba60445a8e',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
appSecret: { type: 'string' },
token: { type: 'string' },
},
required: ['appSecret', 'token'],
} as const;
// eslint-disable-next-line import/no-default-export
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
export default class extends Endpoint<'auth/session/userkey'> {
name = 'auth/session/userkey' as const;
constructor(
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
@ -75,14 +24,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private userEntityService: UserEntityService,
) {
super(meta, paramDef, async (ps, me) => {
super(async (ps, me) => {
// Lookup app
const app = await this.appsRepository.findOneBy({
secret: ps.appSecret,
});
if (app == null) {
throw new ApiError(meta.errors.noSuchApp);
throw new ApiError(this.meta.errors.noSuchApp);
}
// Fetch token
@ -92,11 +41,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
});
if (session == null) {
throw new ApiError(meta.errors.noSuchSession);
throw new ApiError(this.meta.errors.noSuchSession);
}
if (session.userId == null) {
throw new ApiError(meta.errors.pendingSession);
throw new ApiError(this.meta.errors.pendingSession);
}
// Lookup access token