Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peter/v2 hot fixes #84

Merged
merged 4 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kinde-oss/kinde-auth-nextjs",
"version": "2.0.0-alpha.2",
"version": "2.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

"description": "Kinde Auth SDK for NextJS",
"main": "dist/cjs/index.js",
"module": "dist/index.js",
Expand Down
5 changes: 1 addition & 4 deletions src/authMiddleware/authMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import jwt_decode from 'jwt-decode';
import {NextResponse} from 'next/server';
import {config} from '../config/index';
import {isTokenValid} from '../utils/pageRouter/isTokenValid';
Expand All @@ -10,11 +9,10 @@ export function authMiddleware(request) {
let isAuthenticated = false;
const nextUrl = trimTrailingSlash(request.nextUrl.href);
const logoutUrl = trimTrailingSlash(config.postLogoutRedirectURL);
const kinde_token = request.cookies.get('kinde_token');
const kinde_token = request.cookies.get('access_token');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterphanouvong is this right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaveOrDead yea, using TS SDK sets access_token in cookies instead of kinde_token

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I see. Seems this would create breaking changes for anyone accessing the cookie directly.

Could we instead update the TS SDK to allow a cookie name to be passed? That way we can pass kinde_token from the NextJS SDK which keeps it working as it was for existing users?

const isLogoutUrl = nextUrl === logoutUrl;

if (kinde_token) {
const payload = jwt_decode(JSON.parse(kinde_token.value).access_token);
isAuthenticated = true;
}

Expand Down Expand Up @@ -49,7 +47,6 @@ const handleMiddleware = async (req, options, onSuccess) => {
config.redirectURL
)
);
response.headers.set('x-hello-from-middleware2', 'hello');
return response;
}

Expand Down
35 changes: 22 additions & 13 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import {GrantType} from '@kinde-oss/kinde-typescript-sdk';
import {version} from '../utils/version';

/**
* @type {import('../../types').KindeState}
*/
const initialState = {
user: null,
isLoading: true,
checkSession: null,
accessToken: null,
getClaim: null,
getFlag: null,
getToken: null,
getBooleanFlag: null,
getStringFlag: null,
getIntegerFlag: null,
getPermission: null,
getPermissions: null,
permissions: null,
idToken: null,
isAuthenticated: false,
isLoading: true,
organization: null,
userOrganizations: null
permissions: [],
user: null,
userOrganiaztions: [],
getAccessToken: () => null,
getBooleanFlag: () => null,
getClaim: () => null,
getFlag: () => null,
getIdToken: () => null,
getIntegerFlag: () => null,
getOrganization: () => null,
getPermission: () => null,
getPermissions: () => [],
getStringFlag: () => null,
getToken: () => null,
getUser: () => null,
getUserOrganizations: () => null
};

const SESSION_PREFIX = 'pkce-verifier';
Expand Down
Loading