mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-05 04:02:21 +02:00
♻️ Create backend package (#643)
This commit is contained in:
parent
7fc08c6736
commit
05fe2edaea
68 changed files with 476 additions and 391 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue