Skip to content

Commit

Permalink
fix: pages router
Browse files Browse the repository at this point in the history
  • Loading branch information
peterphanouvong committed Nov 16, 2023
1 parent d29bca2 commit 3fc4e59
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 9 deletions.
7 changes: 7 additions & 0 deletions components/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kinde-oss/kinde-auth-nextjs/components",
"private": true,
"main": "../dist/components/cjs/index.js",
"module": "../dist/components/index.js",
"typings": "../dist/components/index.d.ts"
}
7 changes: 7 additions & 0 deletions middleware/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kinde-oss/kinde-auth-nextjs/middleware",
"private": true,
"main": "../dist/middleware/cjs/index.js",
"module": "../dist/middleware/index.js",
"typings": "../dist/middleware/index.d.ts"
}
7 changes: 7 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kinde-oss/kinde-auth-nextjs/server",
"private": true,
"main": "../dist/server/cjs/index.js",
"module": "../dist/server/index.js",
"typings": "../dist/server/index.d.ts"
}
5 changes: 5 additions & 0 deletions src/handlers/callback.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import {config} from '../config/index';
import RouterClient from '../routerClients/RouterClient';

/**
*
* @param {RouterClient} routerClient
*/
export const callback = async (routerClient) => {
const postLoginRedirectURLFromMemory =
await routerClient.sessionManager.getSessionItem('post_login_redirect_url');
Expand Down
8 changes: 7 additions & 1 deletion src/handlers/logout.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import RouterClient from '../routerClients/RouterClient';

/**
*
* @param {RouterClient} routerClient
*/
export const logout = async (routerClient) => {
const authUrl = await routerClient.kindeClient.logout(
routerClient.sessionManager
);

routerClient.redirect(authUrl);
routerClient.redirect(authUrl.toString());
};
7 changes: 7 additions & 0 deletions src/handlers/setup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import RouterClient from '../routerClients/RouterClient';

/**
*
* @param {RouterClient} routerClient
* @returns
*/
export const setup = async (routerClient) => {
const user = await routerClient.sessionManager.getSessionItem('user');
if (user) {
Expand Down
2 changes: 1 addition & 1 deletion src/routerClients/AppRouterClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class AppRouterClient extends RouterClient {
* @param {{status: number}} status
* @returns
*/
json(data, status) {
json(data, status = {status: 200}) {
return Response.json(data, status);
}

Expand Down
8 changes: 4 additions & 4 deletions src/routerClients/PagesRouterClient.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createKindeServerClient} from '@kinde-oss/kinde-typescript-sdk';
import {config} from '../config/index';
import {sessionManager} from '../session/sessionManager';
import {pageRouterSessionManager} from '../session/sessionManager';
import RouterClient from './RouterClient';

// @ts-ignore
Expand All @@ -21,7 +21,7 @@ export default class PagesRouterClient extends RouterClient {
this.res = res;
this.req = req;
this.searchParams = this.url.searchParams;
this.sessionManager = sessionManager(req, res);
this.sessionManager = pageRouterSessionManager(req, res);
}

/**
Expand All @@ -30,7 +30,7 @@ export default class PagesRouterClient extends RouterClient {
* @returns
*/
redirect(url) {
return this.res.redirect(url);
return this.res.redirect(url.toString());
}

getUrl() {
Expand All @@ -42,7 +42,7 @@ export default class PagesRouterClient extends RouterClient {
* @param {{status: number}} status
* @returns
*/
json(data, status) {
json(data, status = {status: 200}) {
return this.res.status(status.status).json(data);
}

Expand Down
4 changes: 2 additions & 2 deletions src/session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {isAuthenticatedFactory} from './isAuthenticated';

/**
*
* @param {import('next').NextApiRequest} [req]
* @param {import('next').NextApiResponse} [res]
* @param {import('next').NextApiRequest | Request} [req]
* @param {import('next').NextApiResponse | Response} [res]
* @returns
*/
export default function (req, res) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/version.js

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

2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
// "Go to Definition" in VSCode
"declarationMap": true,
"esModuleInterop": true
// "checkJs": true,
// "strict": true
}
}

0 comments on commit 3fc4e59

Please sign in to comment.