In React Router, a common pattern for protected route is like this:
async function protectedRouteLoader(request) {
const user = await checkAuthenticatedUser(request);
if (user == null) {
return redirect(LOGIN_URI);
}
const data = await loadRouteData(request, user);
return data;
}
const route = {
loader: protectedRouteLoader,
Component: DataViewComponent,
};
Currently (@authgear/web@2.15.0) the container only exposes startAuthentication, which internally calls authorizeEndpoint and redirect directly by setting location.href. Ideally we could call authorizeEndpoint directly and do redirect(await container.authorizeEndpoint()). A workaround is to call startAuthentication and await forever, but it would not work if a server-side framework is involved.
In React Router, a common pattern for protected route is like this:
Currently (
@authgear/web@2.15.0) the container only exposesstartAuthentication, which internally callsauthorizeEndpointand redirect directly by settinglocation.href. Ideally we could callauthorizeEndpointdirectly and doredirect(await container.authorizeEndpoint()). A workaround is to callstartAuthenticationand await forever, but it would not work if a server-side framework is involved.