umami/pages/index.js

41 lines
826 B
JavaScript
Raw Normal View History

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-26 01:31:07 +02:00
import cookies from 'next-cookies';
2020-07-24 04:56:55 +02:00
import Layout from 'components/Layout';
2020-07-26 01:31:07 +02:00
import { verifySecureToken } from 'lib/crypto';
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-26 01:31:07 +02:00
<h2>
You've successfully logged in as <b>{username}</b>.
</h2>
<Link href="/logout">
<a>Logout 🡒</a>
</Link>
2020-07-17 10:03:38 +02:00
</Layout>
);
}
2020-07-26 01:31:07 +02:00
export async function getServerSideProps(context) {
const token = cookies(context)['umami.auth'];
try {
const payload = await verifySecureToken(token);
return {
props: {
username: payload.username,
},
};
} catch {
const { res } = context;
res.statusCode = 303;
res.setHeader('Location', '/login');
res.end();
}
return { props: {} };
}