import express from 'express' ; import { authCookieName } from '@config' ; import feature from '@config/feature.config' ; import { loadUserInfo } from '@app/redux/actions/user' ; export default ( ) : object => { const router = express . Router ( ) ; router . post ( '/in' , ( req , res ) => { let access_token = req . body . access_token ; res . cookie ( authCookieName , access_token , { path : '/' , httpOnly : true , maxAge : feature . tokenMaxAge } ) ; res . send ( { success : true } ) ; } ) ; router . post ( '/out' , ( req , res ) => { res . clearCookie ( authCookieName ) ; res . send ( { success : true } ) ; } ) ; router . post ( '/check' , async ( req , res ) => { let accessToken = req . cookies [ authCookieName ] || '' ; let result = { success : true , signIn : false , error : null , accessToken } ; if ( accessToken ) { let [ err , res ] = await loadUserInfo ( { accessToken } ) ( null , null ) ; if ( res ) { result . signIn = true ; result . userInfo = res ; } else { result . error = err ; } } res . send ( result ) ; } ) ; return router ; } ;