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

Add additional configuration to control the return pathname #9

Merged
merged 2 commits into from
Mar 27, 2024

Conversation

benoitgrelard
Copy link
Contributor

@benoitgrelard benoitgrelard commented Mar 26, 2024

This PR handles a couple things:

  • Changes the way the callback route is configured, to enable passing some options (notably an option to configure the default return pathname)
  • Handles returning the user to the pathname they attempted before they were thrown to sign-in when ensureSignedIn is true in getUser()

Fixes #11

src/authkit-callback-route.ts Outdated Show resolved Hide resolved
src/get-authorization-url.ts Show resolved Hide resolved
src/authkit-callback-route.ts Outdated Show resolved Hide resolved
import { authkitMiddleware } from './middleware.js';
import { getUser } from './session.js';
import { getSignInUrl, signOut } from './auth.js';
import { Impersonation } from './impersonation.js';

export {
authkitCallbackRoute,
handleAuth,
Copy link
Contributor

Choose a reason for hiding this comment

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

This kinda breaks backwards compatibility right? Wonder if that means we should release a major version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Typically I think that's fine given we're in the 0.x range.

From SemVer:

Major version zero (0.y.z) is for initial development. Anything MAY change at any time. The public API SHOULD NOT be considered stable.

return async function GET(request: NextRequest) {
const code = request.nextUrl.searchParams.get('code');
const state = request.nextUrl.searchParams.get('state');
const returnPathname = state ? JSON.parse(atob(state)).returnPathname : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

What should happen if state doesn't contain valid JSON?

Right now it will throw, which is probably fine if the state was tampered with (maliciously or not), but wanted to point it out in case anyone had other preferences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think it's fine for now considering it would only be an issue if tampered with.

@benoitgrelard benoitgrelard requested a review from PaulAsjes March 27, 2024 12:33
@benoitgrelard benoitgrelard merged commit 678e11a into main Mar 27, 2024
2 checks passed
@benoitgrelard benoitgrelard deleted the return-pathname branch March 27, 2024 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Implement Automatic Configuration for Redirecting Users After Login
3 participants