import { PUBLIC_URL } from '$env/static/public';

export async function UserCheck(){

  let token = localStorage.getItem('BPChat')
    const response = await fetch(`${PUBLIC_URL}/api/users/me`, {
      method: 'GET',
      credentials:'include',
      headers: {'Authorization': token },
    })
  
    if(response.ok){
      const data = await response.json();
      return data
    }

    else{
      console.log(response)
      location.assign('/login')
    }
  }

export async function handleLogout() {

  localStorage.removeItem('BPChat')
  location.assign('/login')

}
  
  