Removed redirect clientside session logic from pages and moved to shell
This commit is contained in:
parent
17b880335a
commit
880c4e91a3
8 changed files with 27 additions and 40 deletions
|
@ -27,11 +27,14 @@ export default function Shell(props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const logoutHandler = () => {
|
const logoutHandler = () => {
|
||||||
signOut();
|
signOut({ redirect: false }).then( () => router.push('/auth/logout') );
|
||||||
router.push('/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
if ( ! loading && ! session ) {
|
||||||
|
router.replace('/auth/login');
|
||||||
|
}
|
||||||
|
|
||||||
|
return session && (
|
||||||
<div>
|
<div>
|
||||||
<div className="bg-gray-800 pb-32">
|
<div className="bg-gray-800 pb-32">
|
||||||
<nav className="bg-gray-800">
|
<nav className="bg-gray-800">
|
||||||
|
|
|
@ -17,10 +17,6 @@ export default function EventType(props) {
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <p className="text-gray-400">Loading...</p>;
|
return <p className="text-gray-400">Loading...</p>;
|
||||||
} else {
|
|
||||||
if (!session) {
|
|
||||||
window.location.href = "/auth/login";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateEventTypeHandler(event) {
|
async function updateEventTypeHandler(event) {
|
||||||
|
@ -164,7 +160,9 @@ export default function EventType(props) {
|
||||||
|
|
||||||
export async function getServerSideProps(context) {
|
export async function getServerSideProps(context) {
|
||||||
const session = await getSession(context);
|
const session = await getSession(context);
|
||||||
|
if (!session) {
|
||||||
|
return { redirect: { permanent: false, destination: '/auth/login' } };
|
||||||
|
}
|
||||||
const user = await prisma.user.findFirst({
|
const user = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
email: session.user.email,
|
email: session.user.email,
|
||||||
|
|
|
@ -28,10 +28,6 @@ export default function Availability(props) {
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <p className="text-gray-400">Loading...</p>;
|
return <p className="text-gray-400">Loading...</p>;
|
||||||
} else {
|
|
||||||
if (!session) {
|
|
||||||
window.location.href = "/auth/login";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleAddModal() {
|
function toggleAddModal() {
|
||||||
|
@ -353,6 +349,9 @@ export default function Availability(props) {
|
||||||
|
|
||||||
export async function getServerSideProps(context) {
|
export async function getServerSideProps(context) {
|
||||||
const session = await getSession(context);
|
const session = await getSession(context);
|
||||||
|
if (!session) {
|
||||||
|
return { redirect: { permanent: false, destination: '/auth/login' } };
|
||||||
|
}
|
||||||
|
|
||||||
const user = await prisma.user.findFirst({
|
const user = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
|
|
|
@ -6,14 +6,9 @@ import { signIn, useSession, getSession } from 'next-auth/client';
|
||||||
|
|
||||||
export default function Home(props) {
|
export default function Home(props) {
|
||||||
const [ session, loading ] = useSession();
|
const [ session, loading ] = useSession();
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <p className="text-gray-400">Loading...</p>;
|
return <p className="text-gray-400">Loading...</p>;
|
||||||
}
|
}
|
||||||
if (!session) {
|
|
||||||
window.location.href = "/auth/login";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -13,10 +13,6 @@ export default function integration(props) {
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <p className="text-gray-400">Loading...</p>;
|
return <p className="text-gray-400">Loading...</p>;
|
||||||
} else {
|
|
||||||
if (!session) {
|
|
||||||
window.location.href = "/";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleShowAPIKey() {
|
function toggleShowAPIKey() {
|
||||||
|
|
|
@ -13,10 +13,6 @@ export default function Home({ integrations }) {
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <p className="text-gray-400">Loading...</p>;
|
return <p className="text-gray-400">Loading...</p>;
|
||||||
} else {
|
|
||||||
if (!session) {
|
|
||||||
window.location.href = "/";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleAddModal() {
|
function toggleAddModal() {
|
||||||
|
@ -181,7 +177,9 @@ const validJson = (jsonString: string) => {
|
||||||
|
|
||||||
export async function getServerSideProps(context) {
|
export async function getServerSideProps(context) {
|
||||||
const session = await getSession(context);
|
const session = await getSession(context);
|
||||||
|
if (!session) {
|
||||||
|
return { redirect: { permanent: false, destination: '/auth/login' } };
|
||||||
|
}
|
||||||
const user = await prisma.user.findFirst({
|
const user = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
email: session.user.email,
|
email: session.user.email,
|
||||||
|
|
|
@ -15,10 +15,6 @@ export default function Settings(props) {
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <p className="text-gray-400">Loading...</p>;
|
return <p className="text-gray-400">Loading...</p>;
|
||||||
} else {
|
|
||||||
if (!session) {
|
|
||||||
window.location.href = "/auth/login";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const closeSuccessModal = () => { setSuccessModalOpen(false); }
|
const closeSuccessModal = () => { setSuccessModalOpen(false); }
|
||||||
|
@ -88,6 +84,9 @@ export default function Settings(props) {
|
||||||
|
|
||||||
export async function getServerSideProps(context) {
|
export async function getServerSideProps(context) {
|
||||||
const session = await getSession(context);
|
const session = await getSession(context);
|
||||||
|
if (!session) {
|
||||||
|
return { redirect: { permanent: false, destination: '/auth/login' } };
|
||||||
|
}
|
||||||
|
|
||||||
const user = await prisma.user.findFirst({
|
const user = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
|
|
|
@ -22,10 +22,6 @@ export default function Settings(props) {
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <p className="text-gray-400">Loading...</p>;
|
return <p className="text-gray-400">Loading...</p>;
|
||||||
} else {
|
|
||||||
if (!session) {
|
|
||||||
window.location.href = "/auth/login";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const closeSuccessModal = () => { setSuccessModalOpen(false); }
|
const closeSuccessModal = () => { setSuccessModalOpen(false); }
|
||||||
|
@ -159,6 +155,9 @@ export default function Settings(props) {
|
||||||
|
|
||||||
export async function getServerSideProps(context) {
|
export async function getServerSideProps(context) {
|
||||||
const session = await getSession(context);
|
const session = await getSession(context);
|
||||||
|
if (!session) {
|
||||||
|
return { redirect: { permanent: false, destination: '/auth/login' } };
|
||||||
|
}
|
||||||
|
|
||||||
const user = await prisma.user.findFirst({
|
const user = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
|
|
Loading…
Reference in a new issue