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