2017-03-08 18:50:09 +00:00
|
|
|
import $ from 'cafy';
|
2018-03-29 11:32:18 +00:00
|
|
|
import AuthSess, { pack } from '../../../../../models/auth-session';
|
2018-11-02 04:47:44 +00:00
|
|
|
import define from '../../../define';
|
2019-02-22 02:46:58 +00:00
|
|
|
import { ApiError } from '../../../error';
|
2018-11-02 03:49:08 +00:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
requireCredential: false,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
token: {
|
|
|
|
validator: $.str
|
|
|
|
}
|
2019-02-22 02:46:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchSession: {
|
|
|
|
message: 'No such session.',
|
|
|
|
code: 'NO_SUCH_SESSION',
|
|
|
|
id: 'bd72c97d-eba7-4adb-a467-f171b8847250'
|
|
|
|
}
|
2018-11-02 03:49:08 +00:00
|
|
|
}
|
|
|
|
};
|
2016-12-28 22:49:51 +00:00
|
|
|
|
2019-02-22 02:46:58 +00:00
|
|
|
export default define(meta, async (ps, user) => {
|
2016-12-28 22:49:51 +00:00
|
|
|
// Lookup session
|
|
|
|
const session = await AuthSess.findOne({
|
2018-11-02 03:49:08 +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-02-22 02:46:58 +00:00
|
|
|
return await pack(session, user);
|
|
|
|
});
|