1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/src/hooks/api/getters/useAuth/useAuthUser.ts
olav 213e8950d3 refactor: port login auth to TS/SWR (#680)
* refactor: allow existing tsc errors

* refactor: add missing component key

* refactor: port login auth to TS/SWR

* refactor: replace incorrect CREATE_TAG_TYPE with UPDATE_TAG_TYPE

* refactor: fix AccessProvider permission mocks

* refactor: add types to AccessContext

* refactor: fix file extension

* refactor: remove default export

* refactor: remove unused IAddedUser interface

* refactor: comment on the permissions prop

* refactor: split auth hooks

* feat: auth tests

* fix: setup separate e2e tests

* fix: naming

* fix: lint

* fix: spec path

* fix: missing store

* feat: add more tests

Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com>
2022-02-10 17:04:10 +01:00

22 lines
535 B
TypeScript

import { IUser } from '../../../../interfaces/user';
import { useAuthEndpoint } from './useAuthEndpoint';
interface IUseAuthUserOutput {
user?: IUser;
refetchUser: () => void;
loading: boolean;
error?: Error;
}
export const useAuthUser = (): IUseAuthUserOutput => {
const auth = useAuthEndpoint();
const user = auth.data && 'user' in auth.data ? auth.data.user : undefined;
return {
user,
refetchUser: auth.refetchAuth,
loading: auth.loading,
error: auth.error,
};
};