egirlskey/src/server/api/endpoints/auth/session/show.ts

32 lines
657 B
TypeScript
Raw Normal View History

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-06-18 00:54:53 +00:00
import { ILocalUser } from '../../../../../models/user';
2018-11-02 03:49:08 +00:00
import getParams from '../../../get-params';
export const meta = {
requireCredential: false,
params: {
token: {
validator: $.str
}
}
};
2016-12-28 22:49:51 +00:00
2018-07-05 17:58:29 +00:00
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
2018-11-02 03:49:08 +00:00
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
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) {
return rej('session not found');
}
// Response
2018-02-01 23:21:30 +00:00
res(await pack(session, user));
2016-12-28 22:49:51 +00:00
});