Make get_session() readonly and throw an exception if session cannot be found rather...
[ndcode_site.git] / _lib / get_account.jst
1 let jst_server = (await import('@ndcode/jst_server')).default
2
3 return async (root, session) => {
4   let signed_in_as = await session.get_json('signed_in_as')
5   if (signed_in_as === undefined)
6     throw new jst_server.Problem(
7       'Unauthorized',
8       'Please sign in first.',
9       401
10     )
11   let accounts = await root.get('accounts')
12   let account = accounts.get(signed_in_as)
13   if (account === undefined)
14     throw new jst_server.Problem(
15       'Account expired',
16       'Database is inconsistent, please sign out and recreate your account.'
17       507
18     )
19   return account
20 }