Add force SSL check.

This commit is contained in:
Mike Cao 2020-10-03 21:54:21 -07:00
parent fc22f5969c
commit 4cafa68e23
4 changed files with 18 additions and 4 deletions

14
hooks/useForceSSL.js Normal file
View file

@ -0,0 +1,14 @@
import { useEffect } from 'react';
import { useRouter } from 'next/router';
export default function useForceSSL(enabled) {
const router = useRouter();
useEffect(() => {
if (enabled && typeof window !== 'undefined' && /^http:\/\//.test(location.href)) {
router.push(location.href.replace(/^http:\/\//, 'https://'));
}
}, [enabled]);
return null;
}