mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
daily auth hotfix (#757)
Co-authored-by: Igor Loskutov <igor.loskutoff@gmail.com>
This commit is contained in:
@@ -23,7 +23,6 @@ export default function DailyRoom({ meeting }: DailyRoomProps) {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const auth = useAuth();
|
const auth = useAuth();
|
||||||
const authStatus = auth.status;
|
|
||||||
const authLastUserId = auth.lastUserId;
|
const authLastUserId = auth.lastUserId;
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const joinMutation = useRoomJoinMeeting();
|
const joinMutation = useRoomJoinMeeting();
|
||||||
@@ -32,7 +31,7 @@ export default function DailyRoom({ meeting }: DailyRoomProps) {
|
|||||||
const roomName = params?.roomName as string;
|
const roomName = params?.roomName as string;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (authLastUserId === null || !meeting?.id || !roomName) return;
|
if (authLastUserId === undefined || !meeting?.id || !roomName) return;
|
||||||
|
|
||||||
const join = async () => {
|
const join = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -60,7 +59,8 @@ export default function DailyRoom({ meeting }: DailyRoomProps) {
|
|||||||
}, [router]);
|
}, [router]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!authLastUserId || !roomUrl || !containerRef.current) return;
|
if (authLastUserId === undefined || !roomUrl || !containerRef.current)
|
||||||
|
return;
|
||||||
|
|
||||||
let frame: DailyCall | null = null;
|
let frame: DailyCall | null = null;
|
||||||
let destroyed = false;
|
let destroyed = false;
|
||||||
@@ -122,7 +122,7 @@ export default function DailyRoom({ meeting }: DailyRoomProps) {
|
|||||||
};
|
};
|
||||||
}, [roomUrl, authLastUserId, handleLeave]);
|
}, [roomUrl, authLastUserId, handleLeave]);
|
||||||
|
|
||||||
if (!authLastUserId) {
|
if (authLastUserId === undefined) {
|
||||||
return (
|
return (
|
||||||
<Center width="100vw" height="100vh">
|
<Center width="100vw" height="100vh">
|
||||||
<Spinner size="xl" />
|
<Spinner size="xl" />
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ type AuthContextType = (
|
|||||||
signIn: typeof signIn;
|
signIn: typeof signIn;
|
||||||
signOut: typeof signOut;
|
signOut: typeof signOut;
|
||||||
// TODO probably rename isLoading to isReloading and make THIS field "isLoading"
|
// TODO probably rename isLoading to isReloading and make THIS field "isLoading"
|
||||||
lastUserId: CustomSession["user"]["id"] | null;
|
// undefined is "not known", null is "is certainly logged out"
|
||||||
|
lastUserId: CustomSession["user"]["id"] | null | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||||
@@ -43,13 +44,15 @@ const noopAuthContext: AuthContextType = {
|
|||||||
signOut: async () => {
|
signOut: async () => {
|
||||||
throw new Error("signOut not supposed to be called");
|
throw new Error("signOut not supposed to be called");
|
||||||
},
|
},
|
||||||
lastUserId: null,
|
lastUserId: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||||
const { data: session, status, update } = useNextAuthSession();
|
const { data: session, status, update } = useNextAuthSession();
|
||||||
// referential comparison done in component, must be primitive /or cached
|
// referential comparison done in component, must be primitive /or cached
|
||||||
const lastUserId = useRef<CustomSession["user"]["id"] | null>(null);
|
const lastUserId = useRef<CustomSession["user"]["id"] | null | undefined>(
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
const contextValue: AuthContextType = isAuthEnabled
|
const contextValue: AuthContextType = isAuthEnabled
|
||||||
? {
|
? {
|
||||||
@@ -78,6 +81,8 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|||||||
case "authenticated": {
|
case "authenticated": {
|
||||||
const customSession = assertCustomSession(session);
|
const customSession = assertCustomSession(session);
|
||||||
if (customSession?.error === REFRESH_ACCESS_TOKEN_ERROR) {
|
if (customSession?.error === REFRESH_ACCESS_TOKEN_ERROR) {
|
||||||
|
// warning: call order-dependent
|
||||||
|
lastUserId.current = null;
|
||||||
// token had expired but next auth still returns "authenticated" so show user unauthenticated state
|
// token had expired but next auth still returns "authenticated" so show user unauthenticated state
|
||||||
return {
|
return {
|
||||||
status: "unauthenticated" as const,
|
status: "unauthenticated" as const,
|
||||||
@@ -100,6 +105,8 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "unauthenticated": {
|
case "unauthenticated": {
|
||||||
|
// warning: call order-dependent
|
||||||
|
lastUserId.current = null;
|
||||||
return { status: "unauthenticated" as const };
|
return { status: "unauthenticated" as const };
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|||||||
Reference in New Issue
Block a user