summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/auth/session/show.ts
blob: 4287950f3e0d6f384e4482b4aa5bc45f4d95e9d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import $ from 'cafy';
import AuthSess, { pack } from '../../../../../models/auth-session';
import define from '../../../define';
import { ApiError } from '../../../error';

export const meta = {
	tags: ['auth'],

	requireCredential: false,

	params: {
		token: {
			validator: $.str
		}
	},

	errors: {
		noSuchSession: {
			message: 'No such session.',
			code: 'NO_SUCH_SESSION',
			id: 'bd72c97d-eba7-4adb-a467-f171b8847250'
		}
	}
};

export default define(meta, async (ps, user) => {
	// Lookup session
	const session = await AuthSess.findOne({
		token: ps.token
	});

	if (session == null) {
		throw new ApiError(meta.errors.noSuchSession);
	}

	return await pack(session, user);
});