-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove auth from other nextjs example too
- Loading branch information
Showing
7 changed files
with
65 additions
and
156 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
import { config } from '@keystone-6/core'; | ||
import { lists } from './src/keystone/schema'; | ||
import { withAuth, session } from './src/keystone/auth'; | ||
import { seedDemoData } from './src/keystone/seed'; | ||
import type { Context } from '.keystone/types'; | ||
|
||
// Next.js deploys need absolute path to sqlite db file | ||
const dbFilePath = `${process.cwd()}/keystone.db`; | ||
export default withAuth( | ||
config({ | ||
db: { | ||
provider: 'sqlite', | ||
url: `file:${dbFilePath}`, | ||
onConnect: async (context: Context) => { | ||
await seedDemoData(context); | ||
}, | ||
|
||
// WARNING: this is only needed for our monorepo examples, dont do this | ||
prismaClientPath: 'node_modules/.myprisma/client', | ||
export default config({ | ||
db: { | ||
provider: 'sqlite', | ||
url: `file:${process.cwd()}/keystone.db`, // next.js requires an absolute path for sqlite | ||
onConnect: async (context: Context) => { | ||
await seedDemoData(context); | ||
}, | ||
lists, | ||
session, | ||
}) | ||
); | ||
|
||
// WARNING: this is only needed for our monorepo examples, dont do this | ||
prismaClientPath: 'node_modules/.myprisma/client', | ||
}, | ||
lists, | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,20 @@ | ||
import type { Context } from '.keystone/types'; | ||
|
||
const demoUsers = [ | ||
{ | ||
email: '[email protected]', | ||
password: 'passw0rd', | ||
name: 'Clark Kent', | ||
}, | ||
{ | ||
email: '[email protected]', | ||
password: 'passw0rd', | ||
name: 'Bruce Wayne', | ||
}, | ||
{ | ||
email: '[email protected]', | ||
password: 'passw0rd', | ||
name: 'Diana Prince', | ||
}, | ||
] as const; | ||
export async function seedDemoData(context: Context) { | ||
if ((await context.db.User.count()) > 0) return; | ||
|
||
const upsertUser = async ({ | ||
context, | ||
user, | ||
}: { | ||
context: Context; | ||
user: { email: string; password: string; name: string }; | ||
}) => { | ||
const userInDb = await context.db.User.findOne({ | ||
where: { email: user.email }, | ||
}); | ||
if (userInDb) { | ||
return userInDb; | ||
for (const user of [ | ||
{ | ||
name: 'Clark', | ||
}, | ||
{ | ||
name: 'Bruce', | ||
}, | ||
{ | ||
name: 'Diana', | ||
}, | ||
] as const) { | ||
await context.db.User.createOne({ data: user }); | ||
} | ||
} | ||
|
||
return context.db.User.createOne({ data: user }); | ||
}; | ||
|
||
export const seedDemoData = (context: Context) => { | ||
const sudoContext = context.sudo(); | ||
return Promise.all(demoUsers.map(u => upsertUser({ context: sudoContext, user: u }))); | ||
}; |
This file contains 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