Skip to content

Commit

Permalink
Remove localStorage watch from AuthUserProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
gigincg committed Jan 6, 2025
1 parent 6b838b8 commit 6956474
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions src/Providers/AuthUserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,15 @@ export default function AuthUserProvider({
otpAuthorized,
}: Props) {
const queryClient = useQueryClient();
const [accessToken, setAccessToken] = useState(
localStorage.getItem(LocalStorageKeys.accessToken),
);

const { data: user, isLoading } = useQuery({
queryKey: ["currentUser"],
queryFn: query(routes.currentUser, { silent: true }),
retry: false,
enabled: !!accessToken,
enabled: !!localStorage.getItem(LocalStorageKeys.accessToken),
});

const [isOTPAuthorized, setIsOTPAuthorized] = useState(false);
console.log("isOTPAuthorized", isOTPAuthorized);

const tokenData: TokenData = JSON.parse(
localStorage.getItem(LocalStorageKeys.patientTokenKey) || "{}",
Expand Down Expand Up @@ -67,17 +63,6 @@ export default function AuthUserProvider({
);
}, [user]);

useEffect(() => {
// Listen for localStorage changes
const listener = (event: StorageEvent) => {
if (event.key === LocalStorageKeys.accessToken) {
setAccessToken(event.newValue);
}
};
addEventListener("storage", listener);
return () => removeEventListener("storage", listener);
}, []);

const signIn = useCallback(
async (creds: { username: string; password: string }) => {
const query = await request(routes.login, { body: creds });
Expand Down

0 comments on commit 6956474

Please sign in to comment.