This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
FunctionProject/website/pages/admin/[slug].js

31 lines
731 B
JavaScript
Raw Normal View History

import { Fragment } from 'react';
import Cookies from "universal-cookie";
import HeadTag from '../../components/HeadTag';
import redirect from '../../utils/redirect';
const AdminFunctionComponent = (props) => {
if (!props.user.isAdmin && typeof window != 'undefined') {
return redirect({}, '/404');
}
return (
<Fragment>
<HeadTag />
<p>{props.slug}</p>
</Fragment>
);
}
export async function getServerSideProps({ req, params }) {
const cookies = new Cookies(req.headers.cookie);
const { slug } = params;
return {
props: {
user: { ...cookies.get('user') },
slug
}
};
}
export default AdminFunctionComponent;