How to access ctx.state.user in a global middleware [strapi v4.14]

Same problem, I want to restrict the media library to authenticated users, but I have the impression that our middleware loads before the session middleware.

export default (_config, { strapi }) => {
    return async (ctx, next) => {
        if (ctx.method === 'GET') {
            if (ctx.url.startsWith('/uploads/')) {
                console.log('ctx.state', ctx.state)
                console.log('ctx.state.user', ctx.state.user)
                console.log('ctx.state.auth', ctx.state.auth)
                console.log('ctx.state.isAuthenticated', ctx.state.isAuthenticated)
                if (!ctx.state.user) {
                    // Rediriger vers une autre route
                    return ctx.redirect('/admin/auth/local');
                }
            }
        }
        await next();
      };
};