Skip to content

Commit

Permalink
fix(experimental-app-router): Resolve onLogin issue on Vercel deploym…
Browse files Browse the repository at this point in the history
…ent (wpengine#1919)
  • Loading branch information
CesarBenavides777 committed Nov 26, 2024
1 parent b098fcb commit 72934d6
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-cobras-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@faustwp/experimental-app-router': minor
---

Update @faustwp/experimental-app-router to account for next 15 changes to cookies and update NextResponse import
10 changes: 7 additions & 3 deletions examples/next/app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@faustwp/core": "^3.1.0",
"@faustwp/experimental-app-router": "^0.4.0",
"graphql": "^16.7.1",
"next": "^14.2.3",
"next": "^15.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand All @@ -26,9 +26,13 @@
},
"devDependencies": {
"@types/node": "^20.6.3",
"@types/react": "^18.2.36",
"@types/react-dom": "^18.2.14",
"@types/react": "npm:types-react@rc",
"@types/react-dom": "npm:types-react-dom@rc",
"next-secure-headers": "^2.2.0",
"typescript": "^5.2.2"
},
"overrides": {
"@types/react": "npm:types-react@rc",
"@types/react-dom": "npm:types-react-dom@rc"
}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/experimental-app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@apollo/experimental-nextjs-app-support": ">=0.11.5",
"@faustwp/cli": ">=1.1.3",
"@faustwp/core": ">=1.1.2",
"next": ">=14.0.0",
"next": ">=15.0.3",
"react": ">=18.0.0",
"react-dom": ">=18.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export async function onLogout() {
'use server';

const wpCookieName = `${getWpUrl()}-rt`;
const cookieStore = cookies();
const cookieStore = await cookies();
const wpCookie = cookieStore.get(wpCookieName);

if (wpCookie?.name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export async function setRefreshToken(
refreshToken: string,
refreshTokenExpiration: number,
) {
const cookieStore = cookies();
// eslint-disable-next-line @typescript-eslint/await-thenable
const cookieStore = await cookies();
const cookieName = `${getWpUrl()}-rt`;

cookieStore.set(cookieName, refreshToken, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { getWpUrl } from '../../faust-core-utils.js';
* @returns string|null
*/
export async function fetchTokens(code?: string) {
const cookieStore = cookies();
// eslint-disable-next-line @typescript-eslint/await-thenable
const cookieStore = await cookies();
const cookieName = `${getWpUrl()}-rt`;

if (!cookieStore.get(cookieName)?.value && !code) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { notFound } from 'next/navigation.js';
import * as server from 'next/server.js';
import { tokenHandler } from './tokenHandler.js';

export async function GetFn(req: Request) {
Expand All @@ -8,7 +7,7 @@ export async function GetFn(req: Request) {
switch (pathname) {
case '/api/faust/token/':
case '/api/faust/token': {
return tokenHandler(req, server);
return tokenHandler(req);
}
default: {
return notFound();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cookies } from 'next/headers.js';
import * as server from 'next/server.js';
import { NextResponse } from 'next/server.js';
import { getWpUrl, getWpSecret } from '../../faust-core-utils.js';

export type AuthorizeResponse = {
Expand All @@ -9,7 +9,7 @@ export type AuthorizeResponse = {
refreshTokenExpiration: number;
};

export async function tokenHandler(req: Request, s: typeof server) {
export async function tokenHandler(req: Request) {
try {
const secretKey = getWpSecret();

Expand All @@ -19,8 +19,8 @@ export async function tokenHandler(req: Request, s: typeof server) {

const { url } = req;
const code = new URL(url).searchParams.get('code') ?? undefined;

const cookieStore = cookies();
// eslint-disable-next-line @typescript-eslint/await-thenable
const cookieStore = await cookies();
const cookieName = `${getWpUrl()}-rt`;
const refreshToken = cookieStore.get(cookieName)?.value;

Expand Down Expand Up @@ -79,7 +79,7 @@ export async function tokenHandler(req: Request, s: typeof server) {
* and expiration.
*/

const res = new s.NextResponse(JSON.stringify(data), {
const res = new NextResponse(JSON.stringify(data), {
status: 200,
});

Expand Down
14 changes: 7 additions & 7 deletions packages/faustwp-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"devDependencies": {
"@apollo/client": "^3.6.6",
"@parcel/watcher": "2.4.1",
"@testing-library/jest-dom": "^5.15.0",
"@testing-library/react": "^14.3.1",
"@types/cookie": "^0.4.1",
Expand All @@ -25,19 +26,18 @@
"@types/testing-library__react": "10.2.0",
"concurrently": "^7.6.0",
"fetch-mock": "9.11.0",
"is-typedarray": "1.0.0",
"jest": "29.7.0",
"jest-serializer": "^28.0.0",
"rimraf": "^3.0.2",
"sass": "^1.80.3",
"shx": "^0.3.4",
"throat": "^6.0.2",
"ts-jest": "^27.0.7",
"ts-loader": "^9.2.6",
"typescript": "^4.4.4",
"jest-serializer": "^28.0.0",
"throat": "^6.0.2",
"w3c-hr-time": "^1.0.2",
"is-typedarray": "1.0.0",
"typedarray-to-buffer": "4.0.0",
"sass": "^1.80.3",
"@parcel/watcher": "2.4.1"
"typescript": "^4.4.4",
"w3c-hr-time": "^1.0.2"
},
"dependencies": {
"@wordpress/hooks": "^3.14.0",
Expand Down

0 comments on commit 72934d6

Please sign in to comment.