auth secured routes
This commit is contained in:
parent
387c19e11a
commit
5472833369
|
@ -4,12 +4,15 @@ import prettyBytes from "pretty-bytes";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import Layout from "../components/Layout";
|
import Layout from "../components/Layout";
|
||||||
|
import authServerSideProps from "../services/authServerSideProps";
|
||||||
|
|
||||||
dayjs.extend(relativeTime);
|
dayjs.extend(relativeTime);
|
||||||
|
|
||||||
const apiPrefix = process.env.NODE_ENV === "development" ? "/api/stubs" : "";
|
const apiPrefix = process.env.NODE_ENV === "development" ? "/api/stubs" : "";
|
||||||
const fetcher = (url) => fetch(url).then((r) => r.json());
|
const fetcher = (url) => fetch(url).then((r) => r.json());
|
||||||
|
|
||||||
|
export const getServerSideProps = authServerSideProps();
|
||||||
|
|
||||||
function SkylinkList({ items = [] }) {
|
function SkylinkList({ items = [] }) {
|
||||||
return (
|
return (
|
||||||
<ul className="divide-y divide-gray-200">
|
<ul className="divide-y divide-gray-200">
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
export default function authServerSideProps(getServerSideProps) {
|
||||||
|
return function authenticate(context) {
|
||||||
|
if (!("ory_kratos_session" in context.req.cookies) || !("skynet-jwt" in context.req.cookies)) {
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
permanent: false,
|
||||||
|
destination: `/api/accounts/login?return_to=${encodeURIComponent(context.resolvedUrl)}`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getServerSideProps) {
|
||||||
|
return getServerSideProps(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { props: {} };
|
||||||
|
};
|
||||||
|
}
|
Reference in New Issue