Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/server/api/routers/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export const accountRouter = createTRPCRouter({
const user = await getSession(ctx.cookies);
const hasExhibitorSession = Boolean(ctx.session?.exhibitorId);

console.log("CHECK LOGGED IN", user, hasExhibitorSession);
if (user != null) {
return {
ok: true,
Expand Down
24 changes: 19 additions & 5 deletions src/shared/exhibitorLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,36 @@ export default function ExhibitorLayout({
const [name, setName] = useState<string>("");
const [editNameState, setEditNameState] = useState<boolean>(false);

// States
const [isLoggedIn, setIsLoggedIn] = useState<boolean>(true);
const [isAdmin, setIsAdmin] = useState<boolean>(false);
const [hasExhibitorSession, setHasExhibitorSession] = useState<boolean>(false);
const [isLoaded, setIsLoaded] = useState<boolean>(false);

const logout = api.admin.logout.useMutation();

const getName = api.exhibitor.getName.useQuery();
const setNameMutation = api.exhibitor.setName.useMutation();


const getIsLoggedIn = api.account.isLoggedIn.useQuery();
const isAdmin = Boolean(getIsLoggedIn.data?.isAdmin);
const hasExhibitorSession = Boolean(getIsLoggedIn.data?.hasExhibitorSession);
const getIsLoggedIn = api.account.isLoggedIn.useQuery(undefined, {
onSuccess: (data: any) => {
setIsLoggedIn(data.ok);
setIsAdmin(data.isAdmin);
setHasExhibitorSession(data.hasExhibitorSession);
setIsLoaded(true);
},
});

useEffect(() => {
if (!getIsLoggedIn.isSuccess) return;
if (!isAdmin && !hasExhibitorSession) {
if (!isLoggedIn) handleLogout();

console.log("LOGGED IN", isAdmin, hasExhibitorSession);
if (isLoaded && !isAdmin && !hasExhibitorSession) {
void router.replace("/logga-in");
}
}, [getIsLoggedIn.isSuccess, hasExhibitorSession, isAdmin, router]);
}, [getIsLoggedIn.isSuccess, isLoggedIn, hasExhibitorSession, isAdmin, isLoaded, router]);

const handleLogout = () => {
//console.log("CALL LOGOUT")
Expand Down
Loading