Last active
September 14, 2021 12:32
-
-
Save magicspon/c48de8bf39099668f7d98cca562caf6d to your computer and use it in GitHub Desktop.
nextAuth/Craft/codegen usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react' | |
import { GetServerSideProps } from 'next' | |
import { | |
providers, | |
getSession, | |
csrfToken, | |
ClientSafeProvider, | |
} from 'next-auth/client' | |
import { getSdk } from '@schema/graphql' | |
import cmsClient from '@healthwave/utils/cms/graphqlClient' | |
interface IPageProps { | |
clients: Record<string, ClientSafeProvider> | |
csrf: string | |
heading: string | |
richText: string | |
} | |
function Index({ clients, csrf, heading, richText }: IPageProps): JSX.Element { | |
return ( | |
<span> | |
it's private! | |
</span> | |
) | |
} | |
export default Index | |
export const getServerSideProps: GetServerSideProps = async (context) => { | |
const { req, res } = context | |
const session = await getSession({ req }) | |
if (session && res && session.accessToken) { | |
res.writeHead(302, { | |
Location: '/dashboard', | |
}) | |
res.end() | |
return { props: {} } | |
} | |
const client = cmsClient() | |
const sdk = getSdk(client) | |
const { entry } = await sdk.HomeQuery() | |
return { | |
props: { | |
session: null, | |
clients: await providers(), | |
csrf: await csrfToken(context), | |
...entry, | |
}, | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query HomeQuery { | |
entry(section: "workspaceHome", siteId: 3) { | |
... on workspaceHome_workspaceHome_Entry { | |
title | |
heading | |
richText | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment