Implement feedback as a JSON API, fix missing await on all post_request() calls
[ndcode_site.git] / api / account / sign_out.json.jst
1 let logjson = (await import('@ndcode/logjson')).default
2
3 return async env => {
4   let globals = await env.site.get_json('/_config/globals.json')
5   let nodemailer_noreply = await env.site.get_nodemailer(
6     '/_config/nodemailer_noreply.json'
7   )
8   let post_request = await _require('/_lib/post_request.jst')
9   let session_cookie = await _require('/_lib/session_cookie.jst')
10   let Problem = await _require('/_lib/Problem.jst')
11
12   await post_request(
13     // env
14     env,
15     // handler
16     async () => {
17       let transaction = await env.site.database.Transaction()
18       try {
19         // initialize env.session_key, set cookie in env.response
20         let session = await session_cookie(env, transaction)
21
22         session.set('signed_in_as', null)
23         await transaction.commit()
24       }
25       catch (error) {
26         transaction.rollback()
27         throw error
28       }
29     }
30   )
31 }