{"size": 851, "ext": "js", "max_stars_repo_path": "app/src/utils/hooks/auth.js", "max_stars_repo_name": "laurentC35/Multi-Stromae-v2", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/src/utils/hooks/auth.js", "max_issues_repo_name": "laurentC35/Multi-Stromae-v2", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/src/utils/hooks/auth.js", "max_forks_repo_name": "laurentC35/Multi-Stromae-v2", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 32.7307692308, "max_line_length": 71, "alphanum_fraction": 0.6568742656}
import { useContext } from 'react';
import { AppContext } from 'App';
import { useReactOidc } from '@axa-fr/react-oidc-context';
import { NONE, OIDC } from 'utils/constants';
import { useHistory } from 'react-router';

export const useAuth = () => {
  const history = useHistory();
  const { authenticationType } = useContext(AppContext);
  if (authenticationType === NONE)
    return {
      authenticationType,
      name: 'Fake User',
      logout: () => history.push('/'),
    };
  if (authenticationType === OIDC) {
    /**
     * Assume this conditional hook does not break anything
     */
    // eslint-disable-next-line react-hooks/rules-of-hooks
    const { oidcUser, login, logout } = useReactOidc();
    return { authenticationType, oidcUser, login, logout };
  }
  throw new Error(`Auth type ${authenticationType} is not recognized`);
};
