umami/pages/index.js

34 lines
689 B
JavaScript
Raw Normal View History

2020-07-17 08:03:38 +00:00
import React from 'react';
2020-07-28 06:52:14 +00:00
import { parse } from 'cookie';
2020-07-24 02:56:55 +00:00
import Layout from 'components/Layout';
2020-07-25 23:31:07 +00:00
import { verifySecureToken } from 'lib/crypto';
import WebsiteList from '../components/WebsiteList';
2020-07-17 08:03:38 +00:00
2020-07-25 23:31:07 +00:00
export default function HomePage({ username }) {
2020-07-17 08:03:38 +00:00
return (
<Layout>
<WebsiteList />
2020-07-17 08:03:38 +00:00
</Layout>
);
}
2020-07-25 23:31:07 +00:00
2020-07-28 06:52:14 +00:00
export async function getServerSideProps({ req, res }) {
2020-07-29 07:16:02 +00:00
const token = parse(req.headers.cookie || '')['umami.auth'];
2020-07-25 23:31:07 +00:00
try {
const payload = await verifySecureToken(token);
return {
props: {
2020-07-26 07:12:42 +00:00
...payload,
2020-07-25 23:31:07 +00:00
},
};
} catch {
res.statusCode = 303;
res.setHeader('Location', '/login');
res.end();
}
return { props: {} };
}