Make get_session() readonly and throw an exception if session cannot be found rather...
[ndcode_site.git] / _lib / get_session.jst
1 let jst_server = (await import('@ndcode/jst_server')).default
2
3 return async (env, root) => {
4   let sessions = await root.get('sessions')
5   let session = await sessions.get(env.session_key)
6   if (session === undefined || env.now >= await session.get_json('expires'))
7     // this should never happen, but could happen if we take more than a day
8     // to process an incoming request, and database is cleaned in the meantime
9     throw new jst_server.Problem(
10       'Session expired',
11       'We took too long to process an incoming request, please try again.'
12       506
13     )
14   return session
15 }