Skip to content

Commit

Permalink
Fix issue with redirectURI in middleware auth mode (#102)
Browse files Browse the repository at this point in the history
* Fix issue with redirectURI in middleware auth mode

* Addressed feedback
  • Loading branch information
PaulAsjes authored Oct 4, 2024
1 parent 8123726 commit 20aebf5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@workos-inc/authkit-nextjs",
"version": "0.12.0",
"version": "0.12.1",
"description": "Authentication and session helpers for using WorkOS & AuthKit with Next.js",
"sideEffects": false,
"type": "module",
Expand Down
4 changes: 1 addition & 3 deletions src/get-authorization-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { GetAuthURLOptions } from './interfaces.js';
import { headers } from 'next/headers';

async function getAuthorizationUrl(options: GetAuthURLOptions = {}) {
const { returnPathname, screenHint, organizationId } = options;

const redirectUri = headers().get('x-redirect-uri');
const { returnPathname, screenHint, organizationId, redirectUri = headers().get('x-redirect-uri') } = options;

return workos.userManagement.getAuthorizationUrl({
provider: 'authkit',
Expand Down
7 changes: 6 additions & 1 deletion src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ async function updateSession(
if (middlewareAuth.enabled && matchedPaths.length === 0 && !session) {
if (debug) console.log('Unauthenticated user on protected route, redirecting to AuthKit');

return NextResponse.redirect(await getAuthorizationUrl({ returnPathname: getReturnPathname(request.url) }));
return NextResponse.redirect(
await getAuthorizationUrl({
returnPathname: getReturnPathname(request.url),
redirectUri: redirectUri ?? WORKOS_REDIRECT_URI,
}),
);
}

// If no session, just continue
Expand Down
2 changes: 1 addition & 1 deletion src/workos.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WorkOS } from '@workos-inc/node';
import { WORKOS_API_HOSTNAME, WORKOS_API_KEY, WORKOS_API_HTTPS, WORKOS_API_PORT } from './env-variables.js';

export const VERSION = '0.12.0';
export const VERSION = '0.12.1';

const options = {
apiHostname: WORKOS_API_HOSTNAME,
Expand Down

0 comments on commit 20aebf5

Please sign in to comment.