Add force SSL check.

This commit is contained in:
Mike Cao committed 2020-10-03 21:54:21 -07:00
1 parent fc22f5969c
commit 4cafa68e23
4 files changed
+18 -4

No files matched your search

+14
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;
}