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

25 lines
583 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';
2016-12-28 22:49:51 +00:00
/**
* Show a session
*/
2018-07-05 17:58:29 +00:00
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
2016-12-28 22:49:51 +00:00
// Get 'token' parameter
2018-05-02 09:06:16 +00:00
const [token, tokenErr] = $.str.get(params.token);
2017-03-03 10:39:41 +00:00
if (tokenErr) return rej('invalid token param');
2016-12-28 22:49:51 +00:00
// Lookup session
const session = await AuthSess.findOne({
token: token
});
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
});