import fetchHelper from './fetchHelper'
import getTokenHelper from './getTokenHelper'

export default async function forceLogoutHelper(event: any, record: any) {
  if([401, 407].includes(Number(record.status || 0))) {
    let token: string = await getTokenHelper(event)
    //@ts-ignore
    setCookie(event, 'logship_user', null)
    
    const res = await fetchHelper(event, 'auth/logout', 'POST', token, {
      token: token,
    })
    if(res) {
      //@ts-ignore
      setCookie(event, 'logship_it', '')
      setCookie(event, 'logship_rt', '')
    }
  }
}