2020-07-17 10:03:38 +02:00
|
|
|
import React from 'react';
|
2020-07-19 07:51:17 +02:00
|
|
|
import Link from 'next/link';
|
2020-07-28 08:52:14 +02:00
|
|
|
import { parse } from 'cookie';
|
2020-07-24 04:56:55 +02:00
|
|
|
import Layout from 'components/Layout';
|
2020-07-28 10:17:45 +02:00
|
|
|
import PageviewsChart from 'components/PageviewsChart';
|
2020-07-26 01:31:07 +02:00
|
|
|
import { verifySecureToken } from 'lib/crypto';
|
2020-07-28 08:52:14 +02:00
|
|
|
import { subDays, endOfDay } from 'date-fns';
|
2020-07-28 10:17:45 +02:00
|
|
|
import WebsiteList from '../components/WebsiteList';
|
2020-07-17 10:03:38 +02:00
|
|
|
|
2020-07-26 01:31:07 +02:00
|
|
|
export default function HomePage({ username }) {
|
2020-07-17 10:03:38 +02:00
|
|
|
return (
|
|
|
|
<Layout>
|
2020-07-28 10:17:45 +02:00
|
|
|
<WebsiteList />
|
2020-07-26 09:12:42 +02:00
|
|
|
<div>
|
2020-07-28 10:17:45 +02:00
|
|
|
<PageviewsChart
|
2020-07-26 09:12:42 +02:00
|
|
|
websiteId={3}
|
2020-07-28 08:52:14 +02:00
|
|
|
startDate={subDays(endOfDay(new Date()), 6)}
|
|
|
|
endDate={endOfDay(new Date())}
|
2020-07-26 09:12:42 +02:00
|
|
|
/>
|
|
|
|
</div>
|
2020-07-26 01:31:07 +02:00
|
|
|
<Link href="/logout">
|
|
|
|
<a>Logout 🡒</a>
|
|
|
|
</Link>
|
2020-07-17 10:03:38 +02:00
|
|
|
</Layout>
|
|
|
|
);
|
|
|
|
}
|
2020-07-26 01:31:07 +02:00
|
|
|
|
2020-07-28 08:52:14 +02:00
|
|
|
export async function getServerSideProps({ req, res }) {
|
2020-07-29 09:16:02 +02:00
|
|
|
const token = parse(req.headers.cookie || '')['umami.auth'];
|
2020-07-26 01:31:07 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
const payload = await verifySecureToken(token);
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
2020-07-26 09:12:42 +02:00
|
|
|
...payload,
|
2020-07-26 01:31:07 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
} catch {
|
|
|
|
res.statusCode = 303;
|
|
|
|
res.setHeader('Location', '/login');
|
|
|
|
res.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
return { props: {} };
|
|
|
|
}
|