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

v5: NextJS improvements #2691

Merged
merged 2 commits into from
Feb 2, 2024
Merged

Conversation

nikosdouvlis
Copy link
Member

@nikosdouvlis nikosdouvlis commented Jan 30, 2024

Description

The auth().redirectToSignIn() helper no longer needs to be explicitly returned when called within the middleware. The following examples are now equivalent:

// Before
export default clerkMiddleware(auth => {
  if (protectedRoute && !auth.user) {
    return auth().redirectToSignIn()
  }
})

// After
export default clerkMiddleware(auth => {
  if (protectedRoute && !auth.user) {
    auth().redirectToSignIn()
  }
})

Calling auth().protect() from a page will now automatically redirect back to the same page by setting redirect_url to the request url before the redirect to the sign-in URL takes place.

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Packages affected

  • @clerk/backend
  • @clerk/chrome-extension
  • @clerk/clerk-js
  • @clerk/clerk-expo
  • @clerk/fastify
  • gatsby-plugin-clerk
  • @clerk/localizations
  • @clerk/nextjs
  • @clerk/clerk-react
  • @clerk/remix
  • @clerk/clerk-sdk-node
  • @clerk/shared
  • @clerk/themes
  • @clerk/types
  • build/tooling/chore

Copy link

changeset-bot bot commented Jan 30, 2024

🦋 Changeset detected

Latest commit: 4cf05ac

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@clerk/backend Patch
@clerk/nextjs Patch
@clerk/fastify Patch
gatsby-plugin-clerk Patch
@clerk/remix Patch
@clerk/clerk-sdk-node Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@nikosdouvlis nikosdouvlis force-pushed the nikos/sdk-1247-next-improvements branch from bfc06d1 to 8f74ed3 Compare February 1, 2024 19:36
Copy link
Member

@panteliselef panteliselef left a comment

Choose a reason for hiding this comment

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

This looks good to me, Is this still WIP ?

Comment on lines +112 to +113
// TODO @nikos: we need to make this more generic
// and move the logic in clerk/backend
Copy link
Member

Choose a reason for hiding this comment

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

Are you referring to a possible helper named copyHeaders ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but also extracting this to clerk/backend

@nikosdouvlis
Copy link
Member Author

This looks good to me, Is this still WIP ?

No :) please review it!

@nikosdouvlis nikosdouvlis force-pushed the nikos/sdk-1247-next-improvements branch 2 times, most recently from c97c276 to bcab882 Compare February 1, 2024 23:06
@@ -1,6 +1,6 @@
import { errorThrower, parsePublishableKey } from './util/shared';

const buildUrl = (_baseUrl: string | URL, _targetUrl: string | URL, _returnBackUrl?: string | URL) => {
const buildUrl = (_baseUrl: string | URL, _targetUrl: string | URL, _returnBackUrl?: string | URL | null) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ why did we prefix all the params with _? I thought we prefix a variable with an underscore to mark it as ignored which is not the case here. Should we rename the params in another PR?

signInUrl: SIGN_IN_URL,
signUpUrl: SIGN_UP_URL,
}).redirectToSignIn;
const clerkUrl = getAuthKeyFromRequest(request, 'ClerkUrl') as AuthStatus;
Copy link
Contributor

Choose a reason for hiding this comment

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

☁️ clerkUrl is of type AuthStatus ? Is this some kind of typo? Also getAuthKeyFromRequest returns string | null | undefined, so the clerkUrl many not have a .toString() method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch @dimkl
TS did not complain as AuthStatus overlaps with string. Let me fix it!

@nikosdouvlis nikosdouvlis force-pushed the nikos/sdk-1247-next-improvements branch from bcab882 to 1fbd905 Compare February 2, 2024 10:46
@nikosdouvlis nikosdouvlis force-pushed the nikos/sdk-1247-next-improvements branch from 1fbd905 to 4cf05ac Compare February 2, 2024 10:55
Copy link
Member

@anagstef anagstef left a comment

Choose a reason for hiding this comment

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

💯

@nikosdouvlis nikosdouvlis merged commit 7b200af into main Feb 2, 2024
7 checks passed
@nikosdouvlis nikosdouvlis deleted the nikos/sdk-1247-next-improvements branch February 2, 2024 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants