plane/lib/redirect.ts
Dakshesh Jain a58abecc0e fix: made withAuthWrapper working
fix: - made wrapper working - used it in protected routes & removed it from public routes
2022-11-25 16:30:41 +05:30

18 lines
435 B
TypeScript

// next imports
import type { NextPageContext } from "next";
import Router from "next/router";
const redirect = (context: NextPageContext, target: any) => {
if (context.res) {
// server
// 303: "See other"
context.res.writeHead(301, { Location: target });
context.res.end();
} else {
// In the browser, we just pretend like this never even happened ;)
Router.push(target);
}
};
export default redirect;