Skip to content

Problem refetching after login/logout #579

@marcospassos

Description

@marcospassos

I've read all issues regarding this topic but I couldn't find any solution for forcing a refetch after login/logout.

const authenticated: RouteRenderMethod = ({Component, props, match}): ResolvedElement | undefined => {
    if (!Component || !props) {
        return undefined;
    }
    
    const required = !match.routes.some(route => route.public === true);

    if (((props as any).me?.user !== null) === required) {
        return <Component {...props} />;
    }

    if (!required) {
        throw new RedirectException(
            match.location.state?.previousLocation ?? routes.home,
            301,
        );
    }

    throw new RedirectException({
        pathname: routes.signin,
        state: {
            previousLocation: match.location,
        },
    }, 301);
};

export const routeConfig: RouteConfig = [
    {
        path: '/',
        query: AppUserQuery,
        Component: App,
        render: authenticated,
        children: [
            {
                path: 'signin',
                public: true,
                name: routes.signin,
                Component: AuthLayout,
                children: [
                    {
                        Component: SignInPage,
                    },
                ],
            },
            {
                path: 'home',
                name: routes.home,
                Component: AdminLayout,
                children: [
                    {
                        query: UserHomePageQuery,
                        Component: HomePage,
                    },
                ],
            },
        ],
    },
];

The problem is that after logging in, the user is redirected to the homepage. However, the render method is called with the previous query result, and the user gets redirected back to the login page.

I've tried the following solutions:

  • Adding a nonce in the prepareVariabes based on a location state flag. Although it forces fetching, the query is executed twice
  • Tried using the retry method based on a location state flag, but it looks like there is no way to call retry in the render method without ending in an infinite loop

Is there any other alternative solution?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions