mirror of
https://github.com/umami-software/umami.git
synced 2026-02-16 10:35:35 +01:00
Login/logout process.
This commit is contained in:
parent
0f0b1e39e7
commit
f947c7770b
10 changed files with 91 additions and 58 deletions
|
|
@ -1,17 +1,40 @@
|
|||
import React from 'react';
|
||||
import Link from 'next/link';
|
||||
import cookies from 'next-cookies';
|
||||
import Layout from 'components/Layout';
|
||||
import Login from 'components/Login';
|
||||
import { verifySecureToken } from 'lib/crypto';
|
||||
|
||||
export default function Home() {
|
||||
export default function HomePage({ username }) {
|
||||
return (
|
||||
<Layout>
|
||||
<Login />
|
||||
<p>
|
||||
<Link href="/test">
|
||||
<a>Test page 🡒</a>
|
||||
</Link>
|
||||
</p>
|
||||
<h2>
|
||||
You've successfully logged in as <b>{username}</b>.
|
||||
</h2>
|
||||
<Link href="/logout">
|
||||
<a>Logout 🡒</a>
|
||||
</Link>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
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: {} };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue