|
|
@ -25,22 +25,24 @@ class CoreApp extends App<AppProps> {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
const { ctx, router } = initialProps;
|
|
|
|
const { ctx, router } = initialProps;
|
|
|
|
let user = undefined;
|
|
|
|
let user = undefined;
|
|
|
|
try {
|
|
|
|
if (ctx.res) {
|
|
|
|
// Attempt to get the user by running a request to the local api
|
|
|
|
try {
|
|
|
|
const response = await axios.get<User>(
|
|
|
|
// Attempt to get the user by running a request to the local api
|
|
|
|
`http://localhost:${process.env.PORT || 3000}/api/v1/auth/me`,
|
|
|
|
const response = await axios.get<User>(
|
|
|
|
{ headers: ctx.req ? { cookie: ctx.req.headers.cookie } : undefined }
|
|
|
|
`http://localhost:${process.env.PORT || 3000}/api/v1/auth/me`,
|
|
|
|
);
|
|
|
|
{ headers: ctx.req ? { cookie: ctx.req.headers.cookie } : undefined }
|
|
|
|
user = response.data;
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
user = response.data;
|
|
|
|
// If there is no user, and ctx.res is set (to check if we are on the server side)
|
|
|
|
} catch (e) {
|
|
|
|
// _AND_ we are not already on the login or setup route, redirect to /login with a 307
|
|
|
|
// If there is no user, and ctx.res is set (to check if we are on the server side)
|
|
|
|
// before anything actually renders
|
|
|
|
// _AND_ we are not already on the login or setup route, redirect to /login with a 307
|
|
|
|
if (ctx.res && !router.pathname.match(/(login|setup)/)) {
|
|
|
|
// before anything actually renders
|
|
|
|
ctx.res.writeHead(307, {
|
|
|
|
if (!router.pathname.match(/(login|setup)/)) {
|
|
|
|
Location: '/login',
|
|
|
|
ctx.res.writeHead(307, {
|
|
|
|
});
|
|
|
|
Location: '/login',
|
|
|
|
ctx.res.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
ctx.res.end();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|