[Fix] Add support for legacy TW_AUTH_TOKEN in useLoggedInUser hook (#3616)

This commit is contained in:
Jonas Daniels
2024-07-08 01:25:11 -07:00
committed by GitHub
parent 36b6ef3e68
commit 230a49be7b
@@ -8,6 +8,13 @@ import {
} from "thirdweb/react";
import type { EnsureLoginResponse } from "../../../app/api/auth/ensure-login/route";
// define "TW_AUTH_TOKEN" to exist on the window object
declare global {
interface Window {
TW_AUTH_TOKEN?: string;
}
}
export function useLoggedInUser(): {
isLoading: boolean;
isLoggedIn: boolean;
@@ -59,6 +66,13 @@ export function useLoggedInUser(): {
if (data.redirectTo) {
router.replace(data.redirectTo);
}
if (data.jwt) {
// necessary for legacy things for now (SDK picks it up from there)
// eslint-disable-next-line react-compiler/react-compiler
window.TW_AUTH_TOKEN = data.jwt;
} else {
window.TW_AUTH_TOKEN = undefined;
}
},
});