<!-- .github/pull_request_template.md --> ## Description <!-- Provide a clear description of the changes in this PR --> ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin.
17 lines
396 B
TypeScript
17 lines
396 B
TypeScript
import { useEffect, useState } from "react";
|
|
import { fetch } from "@/utils";
|
|
import { User } from "./types";
|
|
|
|
export default function useAuthenticatedUser() {
|
|
const [user, setUser] = useState<User>();
|
|
|
|
useEffect(() => {
|
|
if (!user) {
|
|
fetch("/v1/auth/me")
|
|
.then((response) => response.json())
|
|
.then((data) => setUser(data));
|
|
}
|
|
}, [user]);
|
|
|
|
return { user };
|
|
}
|