Skip to content

Commit

Permalink
Merge pull request #137 from kinde-oss/peter/feat-refresh-tokens
Browse files Browse the repository at this point in the history
Peter/feat refresh tokens
  • Loading branch information
DaveOrDead authored Mar 20, 2024
2 parents 3c2bd8b + da7a4b9 commit 85e2ef8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
8 changes: 4 additions & 4 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
Expand Up @@ -57,7 +57,7 @@
},
"dependencies": {
"@babel/preset-env": "^7.23.9",
"@kinde-oss/kinde-typescript-sdk": "^2.7.1",
"@kinde-oss/kinde-typescript-sdk": "^2.8.0",
"cookie": "^0.5.0",
"crypto-js": "^4.1.1",
"jwt-decode": "^3.1.2",
Expand Down
8 changes: 7 additions & 1 deletion src/authMiddleware/authMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ const handleMiddleware = async (req, options, onSuccess) => {

const isReturnToCurrentPage = options?.isReturnToCurrentPage;
const loginPage = options?.loginPage || '/api/auth/login';
const publicPaths = ['/_next', '/favicon.ico'];

let publicPaths = ['/_next', '/favicon.ico'];
if (options?.publicPaths !== undefined) {
if (Array.isArray(options?.publicPaths)) {
publicPaths = options.publicPaths;
}
}

const loginRedirectUrl = isReturnToCurrentPage
? `${loginPage}?post_login_redirect_url=${pathname}`
Expand Down
13 changes: 13 additions & 0 deletions src/session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {getUserOrganizationsFactory} from './getUserOrganizations';
import {isAuthenticatedFactory} from './isAuthenticated';
import {getAccessTokenRawFactory} from './getAccessTokenRaw';
import {getIdTokenRawFactory} from './getIdTokenRaw';
import {kindeClient} from './kindeServerClient';
import {sessionManager} from './sessionManager';

/**
*
Expand All @@ -21,6 +23,17 @@ import {getIdTokenRawFactory} from './getIdTokenRaw';
*/
export default function (req, res) {
return {
refreshTokens: async () => {
try {
const response = await kindeClient.refreshTokens(
sessionManager(req, res)
);
return response;
} catch (error) {
console.error('Error refreshing tokens', error);
return null;
}
},
getAccessToken: getAccessTokenFactory(req, res),
getBooleanFlag: getBooleanFlagFactory(req, res),
getFlag: getFlagFactory(req, res),
Expand Down

0 comments on commit 85e2ef8

Please sign in to comment.