Koa-like middlewares for Next.js Server Side Rendering
SemVer | status | MobX | MobX i18n |
---|---|---|---|
>=0.7 |
✅developing | >=6.11 |
>=0.5 |
<0.7 |
❌deprecated | >=4 <6.11 |
<0.5 |
- Router
- Error logger
- JWT verifier
- Props cache
- i18n loader
- OAuth 2 signer (with common providers)
- GitHub
import {
JWTProps,
RouterProps,
jwtVerifier,
cache,
errorLogger,
router,
translator
} from 'next-ssr-middleware';
import i18n from '../../model/Translation';
import { User, UserModel } from '../../model/User';
type UserDetailPageProps = User & JWTProps & RouterProps;
export const getServerSideProps = compose<{ id: string }, UserDetailPageProps>(
jwtVerifier(), // set `JWT_SECRET` in `.env.local` first
cache(),
errorLogger,
router,
translator(i18n),
async ({ params }) => {
const props = await new UserModel().getOne(params!.id);
return { notFound: !props, props };
}
);
export default function UserDetailPage({
jwtPayload,
route,
name,
summary
}: UserDetailPageProps) {
return (
<>
<h1>
{name} - {route.params!.id}
</h1>
<p>{summary}</p>
</>
);
}