impress-2020/src/app/components/useCurrentUser.js
Matchu 70d3b06742 basic items page, with user permissioning :)
(the permissioning happens on the backend in the prev change! but yeah we send the auth token in the headers, so the backend knows who you are and whether to show you private data)

(also it is just owned items not in any list!)
2020-09-04 05:59:35 -07:00

19 lines
641 B
JavaScript

import { useAuth0 } from "@auth0/auth0-react";
function useCurrentUser() {
const { isLoading, isAuthenticated, user } = useAuth0();
if (isLoading || !isAuthenticated) {
return { id: null, username: null };
}
// NOTE: Users created correctly should have these attributes... but I'm
// coding defensively, because third-party integrations are always a
// bit of a thing, and I don't want failures to crash us!
const id = user.sub?.match(/^auth0\|impress-([0-9]+)$/)?.[1];
const username = user["https://oauth.impress-2020.openneo.net/username"];
return { id, username };
}
export default useCurrentUser;