import { AUTH_SERVICE } from '../config/routes'

export type FailedResponse = {
  error?: string,
  ok: false,
}

export type SuccessResponse = {
  ok: true,
}

export const checkDevice = async (token: string) => {
  const url = `${AUTH_SERVICE}/authorize/check-device?access_token=${token}`

  const config = {
    method: 'GET',
  }

  const response = await fetch(url, config)

  const body: SuccessResponse | FailedResponse = await response.json()

  if (body.ok) return Promise.resolve()

  return Promise.reject(body)
}
