'How to migrate a HOC authentication logic to react-router V6?

I have an application that I would like to migrate to react-router V6, but in this application I am using HOC authentication logic and I don't know how to do the same under react-router V6 with Protected Route ?

Here is my authentication endpoint check :

import React from 'react';
import { useQuery } from '@apollo/client';
import { GET_MY_SESSION } from './queries';

const withAuth= (Component) => (props) => {
  const { data, refetch } = useQuery(GET_MY_SESSION);
  return <Component {...props} session={data} refetch={refetch} />;
};

export default withAuth;

Here is how it's currently used in my application :

//...
import withAuth from '../Auth/withAuth';

const App = ({ session, refetch }) => (
//...
);

export default withAuth(App);

I have searched, But I don't see that it's the best way to be able to reproduce this under react-router V6 with Protected Route. Hoping to have been clear enough, thank you in advance for your help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source