Skip to content

Instantly share code, notes, and snippets.

@magicspon
Last active September 14, 2021 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magicspon/c48de8bf39099668f7d98cca562caf6d to your computer and use it in GitHub Desktop.
Save magicspon/c48de8bf39099668f7d98cca562caf6d to your computer and use it in GitHub Desktop.
nextAuth/Craft/codegen usage
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,
},
}
}
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