mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
compile fix
This commit is contained in:
@@ -19,7 +19,6 @@ import {
|
||||
parseAsStringLiteral,
|
||||
} from "nuqs";
|
||||
import { LuX } from "react-icons/lu";
|
||||
import useSessionUser from "../../lib/useUserId";
|
||||
import type { components } from "../../reflector-api";
|
||||
|
||||
type Room = components["schemas"]["Room"];
|
||||
|
||||
@@ -22,7 +22,7 @@ import { useTranscriptUpdate } from "../../lib/apiHooks";
|
||||
import ShareLink from "./shareLink";
|
||||
import ShareCopy from "./shareCopy";
|
||||
import ShareZulip from "./shareZulip";
|
||||
import useUserId from "../../lib/useUserId";
|
||||
import { useAuth } from "../../lib/AuthProvider";
|
||||
|
||||
type ShareAndPrivacyProps = {
|
||||
finalSummaryRef: any;
|
||||
@@ -85,7 +85,8 @@ export default function ShareAndPrivacy(props: ShareAndPrivacyProps) {
|
||||
}
|
||||
};
|
||||
|
||||
const userId = useUserId();
|
||||
const auth = useAuth();
|
||||
const userId = auth.status === "authenticated" ? auth.user?.id : null;
|
||||
|
||||
useEffect(() => {
|
||||
setIsOwner(!!(requireLogin && userId === props.transcriptResponse.user_id));
|
||||
|
||||
@@ -260,7 +260,9 @@ export default function Room(details: RoomDetails) {
|
||||
const roomName = details.params.roomName;
|
||||
const meeting = useRoomMeeting(roomName);
|
||||
const router = useRouter();
|
||||
const { isLoading, isAuthenticated } = useSessionStatus();
|
||||
const status = useSessionStatus();
|
||||
const isAuthenticated = status === "authenticated";
|
||||
const isLoading = status === "loading" || meeting.loading;
|
||||
|
||||
const roomUrl = meeting?.response?.host_room_url
|
||||
? meeting?.response?.host_room_url
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
import { createContext, useContext, useEffect } from "react";
|
||||
import { useSession as useNextAuthSession } from "next-auth/react";
|
||||
import { configureApiAuth } from "./apiClient";
|
||||
import { assertExtendedToken, CustomSession } from "./types";
|
||||
import {
|
||||
assertExtendedToken,
|
||||
assertExtendedTokenAndUserId,
|
||||
CustomSession,
|
||||
} from "./types";
|
||||
|
||||
type AuthContextType =
|
||||
| { status: "loading" }
|
||||
@@ -19,7 +23,7 @@ const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||
|
||||
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
const { data: session, status } = useNextAuthSession();
|
||||
const customSession = session ? assertExtendedToken(session) : null;
|
||||
const customSession = session ? assertExtendedTokenAndUserId(session) : null;
|
||||
|
||||
const contextValue: AuthContextType =
|
||||
status === "loading"
|
||||
|
||||
@@ -83,7 +83,6 @@ export const authOptions: AuthOptions = {
|
||||
return await lockedRefreshAccessToken(token);
|
||||
},
|
||||
async session({ session, token }) {
|
||||
// TODO no as
|
||||
const extendedToken = token as JWTWithAccessToken;
|
||||
return {
|
||||
...session,
|
||||
@@ -91,7 +90,7 @@ export const authOptions: AuthOptions = {
|
||||
accessTokenExpires: extendedToken.accessTokenExpires,
|
||||
error: extendedToken.error,
|
||||
user: {
|
||||
id: extendedToken.sub,
|
||||
id: assertExists(extendedToken.sub),
|
||||
name: extendedToken.name,
|
||||
email: extendedToken.email,
|
||||
},
|
||||
|
||||
@@ -13,6 +13,9 @@ export interface CustomSession extends Session {
|
||||
accessToken: string;
|
||||
accessTokenExpires: number;
|
||||
error?: string;
|
||||
user: Session["user"] & {
|
||||
id: string;
|
||||
};
|
||||
}
|
||||
|
||||
// assumption that JWT is JWTWithAccessToken - not ideal, TODO find a reason we have to do that
|
||||
@@ -39,3 +42,25 @@ export const assertExtendedToken = <T>(
|
||||
}
|
||||
throw new Error("Token is not extended with access token");
|
||||
};
|
||||
|
||||
export const assertExtendedTokenAndUserId = <U, T extends { user?: U }>(
|
||||
t: T,
|
||||
): T & {
|
||||
accessTokenExpires: number;
|
||||
accessToken: string;
|
||||
user: U & {
|
||||
id: string;
|
||||
};
|
||||
} => {
|
||||
const extendedToken = assertExtendedToken(t);
|
||||
if (typeof (extendedToken.user as any)?.id === "string") {
|
||||
return t as T & {
|
||||
accessTokenExpires: number;
|
||||
accessToken: string;
|
||||
user: U & {
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
throw new Error("Token is not extended with user id");
|
||||
};
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useSession as useNextAuthSession } from "next-auth/react";
|
||||
import { Session } from "next-auth";
|
||||
import { useAuth } from "./AuthProvider";
|
||||
|
||||
const assertUserId = <T>(u: T): T & { id: string } => {
|
||||
if (typeof (u as { id: string }).id !== "string")
|
||||
throw new Error("Expected user.id to be a string");
|
||||
return u as T & { id: string };
|
||||
};
|
||||
|
||||
// the current assumption in useSessionUser is that "useNextAuthSession" also returns user.id, although useNextAuthSession documentation states it doesn't
|
||||
// the hook is to isolate the potential impact and to document this behaviour
|
||||
export default function useUserId() {
|
||||
const auth = useAuth();
|
||||
return auth.status === "authenticated" ? assertUserId(auth.user) : null;
|
||||
}
|
||||
Reference in New Issue
Block a user