import React from 'react';
import { useSearchParams } from 'react-router-dom';
import { Session } from '../services';

export const Auth: React.FC = () => {
  const [searchParams] = useSearchParams();
  const token = searchParams.get('token');

  const baseUrl = `${window.location.protocol}//${window.location.host}`
  if (token) {
    Session.setBearerToken(token);
    window.location.replace(`${baseUrl}/overview`);
  } else {
    Session.resetLastShownComponent();
    Session.resetBearerToken();
    window.location.replace(`${baseUrl}/`);
  }

  return <></>;
};
