mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-12-23 11:21:26 +00:00
Merge pull request #1719 from LemmyNet/fix-cookie-in-catch-all
Fix nonexistent property `req.cookies`
This commit is contained in:
commit
cf9f37fbc4
1 changed files with 8 additions and 1 deletions
|
@ -25,11 +25,15 @@ import { setForwardedHeaders } from "../utils/set-forwarded-headers";
|
||||||
export default async (req: Request, res: Response) => {
|
export default async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const activeRoute = routes.find(route => matchPath(req.path, route));
|
const activeRoute = routes.find(route => matchPath(req.path, route));
|
||||||
let auth = req.cookies ? cookie.parse(req.cookies).jwt : undefined;
|
|
||||||
|
let auth = req.headers.cookie
|
||||||
|
? cookie.parse(req.headers.cookie).jwt
|
||||||
|
: undefined;
|
||||||
|
|
||||||
const getSiteForm: GetSite = { auth };
|
const getSiteForm: GetSite = { auth };
|
||||||
|
|
||||||
const headers = setForwardedHeaders(req.headers);
|
const headers = setForwardedHeaders(req.headers);
|
||||||
|
|
||||||
const client = wrapClient(
|
const client = wrapClient(
|
||||||
new LemmyHttp(getHttpBaseInternal(), { fetchFunction: fetch, headers })
|
new LemmyHttp(getHttpBaseInternal(), { fetchFunction: fetch, headers })
|
||||||
);
|
);
|
||||||
|
@ -43,6 +47,7 @@ export default async (req: Request, res: Response) => {
|
||||||
let routeData: RouteData = {};
|
let routeData: RouteData = {};
|
||||||
let errorPageData: ErrorPageData | undefined = undefined;
|
let errorPageData: ErrorPageData | undefined = undefined;
|
||||||
let try_site = await client.getSite(getSiteForm);
|
let try_site = await client.getSite(getSiteForm);
|
||||||
|
|
||||||
if (try_site.state === "failed" && try_site.msg == "not_logged_in") {
|
if (try_site.state === "failed" && try_site.msg == "not_logged_in") {
|
||||||
console.error(
|
console.error(
|
||||||
"Incorrect JWT token, skipping auth so frontend can remove jwt cookie"
|
"Incorrect JWT token, skipping auth so frontend can remove jwt cookie"
|
||||||
|
@ -91,6 +96,7 @@ export default async (req: Request, res: Response) => {
|
||||||
// Redirect to the 404 if there's an API error
|
// Redirect to the 404 if there's an API error
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(error.msg);
|
console.error(error.msg);
|
||||||
|
|
||||||
if (error.msg === "instance_is_private") {
|
if (error.msg === "instance_is_private") {
|
||||||
return res.redirect(`/signup`);
|
return res.redirect(`/signup`);
|
||||||
} else {
|
} else {
|
||||||
|
@ -119,6 +125,7 @@ export default async (req: Request, res: Response) => {
|
||||||
// If an error is caught here, the error page couldn't even be rendered
|
// If an error is caught here, the error page couldn't even be rendered
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.statusCode = 500;
|
res.statusCode = 500;
|
||||||
|
|
||||||
return res.send(
|
return res.send(
|
||||||
process.env.NODE_ENV === "development" ? err.message : "Server error"
|
process.env.NODE_ENV === "development" ? err.message : "Server error"
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue