2021-08-19 12:55:45 +00:00
|
|
|
import define from '../../../define';
|
|
|
|
import { ApiError } from '../../../error';
|
|
|
|
import { AuthSessions } from '@/models/index';
|
2018-11-02 03:49:08 +00:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 02:20:58 +00:00
|
|
|
tags: ['auth'],
|
|
|
|
|
2022-01-18 13:27:10 +00:00
|
|
|
requireCredential: false,
|
2018-11-02 03:49:08 +00:00
|
|
|
|
2019-02-22 02:46:58 +00:00
|
|
|
errors: {
|
|
|
|
noSuchSession: {
|
|
|
|
message: 'No such session.',
|
|
|
|
code: 'NO_SUCH_SESSION',
|
2021-12-09 14:58:30 +00:00
|
|
|
id: 'bd72c97d-eba7-4adb-a467-f171b8847250',
|
|
|
|
},
|
2021-03-06 13:34:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 13:27:10 +00:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 13:34:11 +00:00
|
|
|
properties: {
|
|
|
|
id: {
|
2022-01-18 13:27:10 +00:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 14:58:30 +00:00
|
|
|
format: 'id',
|
2021-03-06 13:34:11 +00:00
|
|
|
},
|
|
|
|
app: {
|
2022-01-18 13:27:10 +00:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 14:58:30 +00:00
|
|
|
ref: 'App',
|
2021-03-06 13:34:11 +00:00
|
|
|
},
|
|
|
|
token: {
|
2022-01-18 13:27:10 +00:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 13:27:10 +00:00
|
|
|
} as const;
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2022-02-19 05:05:32 +00:00
|
|
|
const paramDef = {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
token: { type: 'string' },
|
|
|
|
},
|
|
|
|
required: ['token'],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 17:12:50 +00:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 05:05:32 +00:00
|
|
|
export default define(meta, paramDef, async (ps, user) => {
|
2016-12-28 22:49:51 +00:00
|
|
|
// Lookup session
|
2019-04-07 12:50:36 +00:00
|
|
|
const session = await AuthSessions.findOne({
|
2021-12-09 14:58:30 +00:00
|
|
|
token: ps.token,
|
2016-12-28 22:49:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (session == null) {
|
2019-02-22 02:46:58 +00:00
|
|
|
throw new ApiError(meta.errors.noSuchSession);
|
2016-12-28 22:49:51 +00:00
|
|
|
}
|
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
return await AuthSessions.pack(session, user);
|
2019-02-22 02:46:58 +00:00
|
|
|
});
|