fix: ssr session on teams page

pull/333/head
mihaic195 2021-07-02 13:28:33 +03:00
parent 6f64df3e75
commit 2008ad263c
No known key found for this signature in database
GPG Key ID: 18E6B791693DB416
2 changed files with 17 additions and 2 deletions

View File

@ -1,8 +1,9 @@
import '../styles/globals.css';
import {createTelemetryClient, TelemetryProvider} from '../lib/telemetry';
import { Provider } from 'next-auth/client';
import type { AppProps } from "next/app"
function MyApp({ Component, pageProps }) {
function MyApp({ Component, pageProps }: AppProps) {
return (
<TelemetryProvider value={createTelemetryClient()}>
<Provider session={pageProps.session}>

View File

@ -1,8 +1,10 @@
import { GetServerSideProps } from "next"
import Head from 'next/head';
import Shell from '../../components/Shell';
import SettingsShell from '../../components/Settings';
import { useEffect, useState } from 'react';
import { useSession } from 'next-auth/client';
import type { Session } from "next-auth"
import { useSession, getSession } from 'next-auth/client';
import {
UsersIcon,
} from "@heroicons/react/outline";
@ -165,3 +167,15 @@ export default function Teams() {
</Shell>
);
}
// Export the `session` prop to use sessions with Server Side Rendering
export const getServerSideProps: GetServerSideProps<{session: Session | null}> = async (context) => {
const session = await getSession(context);
if (!session) {
return { redirect: { permanent: false, destination: '/auth/login' } };
}
return {
props: { session }
}
}