♻️ Create backend package (#643)

This commit is contained in:
Luke Vella 2023-04-03 10:41:19 +01:00 committed by GitHub
parent 7fc08c6736
commit 05fe2edaea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
68 changed files with 476 additions and 391 deletions

View file

@ -1,16 +1,15 @@
import { trpc, UserSession } from "@rallly/backend";
import { useRouter } from "next/router";
import { useTranslation } from "next-i18next";
import React from "react";
import { UserSession } from "@/utils/auth";
import { usePostHog } from "@/utils/posthog";
import { trpc } from "../utils/trpc";
import { useRequiredContext } from "./use-required-context";
export const UserContext = React.createContext<{
user: UserSession & { shortName: string };
refresh: () => void;
isUpdating: boolean;
logout: () => void;
ownsObject: (obj: { userId: string | null }) => boolean;
} | null>(null);
@ -55,13 +54,10 @@ export const UserProvider = (props: {
const queryClient = trpc.useContext();
const { data: user } = trpc.whoami.get.useQuery();
const [isUpdating, setIsUpdating] = React.useState(false);
const router = useRouter();
const logout = trpc.whoami.destroy.useMutation({
onSuccess: async () => {
setIsUpdating(true);
await queryClient.whoami.invalidate();
setIsUpdating(false);
router.push("/logout");
},
});
@ -91,7 +87,6 @@ export const UserProvider = (props: {
return (
<UserContext.Provider
value={{
isUpdating,
user: { ...user, shortName },
refresh: () => {
return queryClient.whoami.invalidate();