Skip to content
This repository has been archived by the owner on Oct 8, 2023. It is now read-only.

Commit

Permalink
Update dependency @keystone-6/core to v4 (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
renovate[bot] authored Dec 6, 2022
1 parent 4cfed84 commit fac7086
Show file tree
Hide file tree
Showing 7 changed files with 683 additions and 375 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-bags-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@opensaas/keystone-nextjs-auth': major
---

Upgrade to `keystone-6/[email protected]`
6 changes: 3 additions & 3 deletions apps/ks-frontend-demo/package.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@
"@babel/preset-typescript": "^7.16.7",
"@babel/runtime": "^7.17.9",
"@babel/runtime-corejs3": "^7.17.9",
"@next/bundle-analyzer": "^12.2.5",
"@next/bundle-analyzer": "^13.0.6",
"@preconstruct/next": "^4.0.0",
"core-js": "^3.20.3",
"date-fns": "^2.28.0",
"deepmerge": "^4.2.2",
"downshift": "^6.1.9",
"eslint-config-next": "^12.2.5",
"eslint-config-next": "^13.0.6",
"graphql": "^16.6.0",
"graphql-tag": "^2.12.6",
"graphql-upload": "^12.0.0",
"lodash": "^4.17.21",
"lodash.debounce": "^4.0.8",
"next": "^12.2.5",
"next": "^13.0.6",
"next-auth": "^4.18.0",
"next-transpile-modules": "^9.1.0",
"nprogress": "^0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start": "keystone prisma migrate deploy && keystone start"
},
"dependencies": {
"@keystone-6/core": "3.1.3",
"@keystone-6/core": "4.0.0",
"@keystone-6/fields-document": "5.0.2",
"@keystone-ui/button": "7.0.2",
"@keystone-ui/core": "5.0.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/keystone-nextjs-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"next-auth": "^4.18.0"
},
"devDependencies": {
"@keystone-6/core": "3.1.3",
"@keystone-6/core": "4.0.0",
"react": "^18.2.0"
},
"peerDependencies": {
"@keystone-6/core": "3.1.3",
"@keystone-6/core": "4.0.0",
"react": "^18.2.0"
},
"publishConfig": {
Expand Down
18 changes: 12 additions & 6 deletions packages/keystone-nextjs-auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
SessionStrategy,
KeystoneContext,
} from '@keystone-6/core/types';
import type { NextApiRequest } from 'next';

import { getSession } from 'next-auth/react';
import { getToken } from 'next-auth/jwt';
import { Provider } from 'next-auth/providers';
Expand Down Expand Up @@ -181,17 +183,19 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
const { get, end, ...sessionStrategy } = _sessionStrategy;
return {
...sessionStrategy,
get: async ({ req, createContext }) => {
get: async ({ context }) => {
const { req } = context;
const pathname = url.parse(req?.url!).pathname!;
let nextSession: Session | JWT | null;
if (!req) return;
if (pathname.includes('/api/auth')) {
return;
}
const sudoContext = createContext({ sudo: true });
const sudoContext = context.sudo();

if (req.headers?.authorization?.split(' ')[0] === 'Bearer') {
nextSession = await getToken({
req,
req: req as NextApiRequest,
secret: sessionSecret,
});
} else {
Expand All @@ -215,7 +219,7 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
data: nextSession.data,
};

const userSession = await get({ req: reqWithUser, createContext });
const userSession = await get({ context });

return {
...userSession,
Expand All @@ -225,12 +229,14 @@ export function createAuth<GeneratedListTypes extends BaseListTypeInfo>({
itemId: nextSession.itemId,
};
},
end: async ({ res, req, createContext }) => {
await end({ res, req, createContext });
end: async ({ context }) => {
await end({ context });
const TOKEN_NAME =
process.env.NODE_ENV === 'production'
? '__Secure-next-auth.session-token'
: 'next-auth.session-token';
const { req, res } = context;
if (!req || !res) return;
res.setHeader(
'Set-Cookie',
cookie.serialize(TOKEN_NAME, '', {
Expand Down
23 changes: 4 additions & 19 deletions packages/keystone-nextjs-auth/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
import type { ServerResponse, IncomingMessage } from 'http';
import type { NextRequest } from 'next/server';
import { Provider } from 'next-auth/providers';
import { CookiesOptions, PagesOptions } from 'next-auth';
import { BaseListTypeInfo, KeystoneConfig, CreateContext } from '@keystone-6/core/types';

type NextAuthResponse = IncomingMessage & NextRequest;
import { BaseListTypeInfo, KeystoneConfig, KeystoneContext } from '@keystone-6/core/types';

export declare type AuthSessionStrategy<StoredSessionData> = {
start: (args: {
res: ServerResponse;
data: any;
createContext: CreateContext;
}) => Promise<string>;
end: (args: {
req: IncomingMessage;
res: ServerResponse;
createContext: CreateContext;
}) => Promise<void>;
get: (args: {
req: NextAuthResponse;
createContext: CreateContext;
}) => Promise<StoredSessionData | undefined>;
start: (args: { data: any; context: KeystoneContext }) => Promise<unknown>;
end: (args: { context: KeystoneContext }) => Promise<unknown>;
get: (args: { context: KeystoneContext }) => Promise<StoredSessionData | undefined>;
};

export type NextAuthProviders = Provider[];
Expand Down
Loading

0 comments on commit fac7086

Please sign in to comment.