Skip to content

Commit

Permalink
fix circular import
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Jun 8, 2023
1 parent 191bca8 commit 15772f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.

This file was deleted.

29 changes: 15 additions & 14 deletions examples/custom-session-next-auth/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,34 @@ import { getContext } from '@keystone-6/core/context';
import { getServerSession } from 'next-auth/next';
import GithubProvider from 'next-auth/providers/github';
import config from './keystone';
import * as PrismaModule from '.myprisma/client';
import type { Context } from '.keystone/types';

// WARNING: this example is for demonstration purposes only
// as with each of our examples, it has not been vetted
// or tested for any particular usage

// WARNING: you need to change this
const sessionSecret = '-- DEV COOKIE SECRET; CHANGE ME --';

let _keystoneContext: Context = (globalThis as any)._keystoneContext;

async function getKeystoneContext() {
if (!_keystoneContext) {
// TODO: this could probably be better
_keystoneContext = getContext(config, await import('.myprisma/client'));
if (process.env.NODE_ENV !== 'production') {
(globalThis as any)._keystoneContext = _keystoneContext;
}
}
return _keystoneContext;
}

// see https://next-auth.js.org/configuration/options for more
export const nextAuthOptions = {
secret: sessionSecret,
callbacks: {
async signIn({ user, account, profile }: any) {
const sudoContext = getKeystoneContext().sudo();
const sudoContext = (await getKeystoneContext()).sudo();
// console.log('Next Auth Sign In Details', { user, account, profile });
// check if the user exists in keystone
const keystoneUser = await sudoContext.query.Author.findOne({
Expand Down Expand Up @@ -52,18 +65,6 @@ export type Session = {
id: string;
};

let _keystoneContext: Context = (globalThis as any)._keystoneContext;

function getKeystoneContext() {
if (!_keystoneContext) {
_keystoneContext = getContext(config, PrismaModule);
if (process.env.NODE_ENV !== 'production') {
(globalThis as any)._keystoneContext = _keystoneContext;
}
}
return _keystoneContext;
}

export const nextAuthSessionStrategy = {
async get({ context }: { context: Context }): Promise<Session | undefined> {
const { req, res } = context;
Expand Down

0 comments on commit 15772f2

Please sign in to comment.