Clerk Changelog

Clerk Expo v2

Category
SDK
Published

Introducing Clerk Expo SDK v2 with support for Expo Web

We are excited to announce that we have released @clerk/clerk-expo v2 with support for Expo Web! This means that you can create universal apps that run on Android, iOS, and the web all with a single codebase!

Getting started

If you haven't already created an Expo app with Clerk you can follow the Expo quickstart guide.

Otherwise, you can update your existing Expo app to the latest version of @clerk/clerk-expo by following the upgrade guide.

Use Clerk's prebuilt components on the web

Adding a sign-in page to your web app is now as easy as adding a single component:

/app/sign-in.web.tsx
import { SignIn } from '@clerk/clerk-expo/web'

export default function Page() {
  return <SignIn />
}

Build universal authentication flows from one codebase

Leverage our hooks to build universal sign-in and sign-up views for Android, iOS, and web all from one codebase 🤯.

Here's an example of a OAuth sign-in flow, using the SDK's useOAuth hook:

/app/sign-in-oauth.tsx
import React from 'react'
import * as WebBrowser from 'expo-web-browser'
import { Text, View, Button } from 'react-native'
import { Link } from 'expo-router'
import { useOAuth } from '@clerk/clerk-expo'
import * as Linking from 'expo-linking'

export const useWarmUpBrowser = () => {
  React.useEffect(() => {
    void WebBrowser.warmUpAsync()
    return () => {
      void WebBrowser.coolDownAsync()
    }
  }, [])
}

const SignInWithOAuth = () => {
  useWarmUpBrowser()

  const { startOAuthFlow } = useOAuth({ strategy: 'oauth_google' })

  const onPress = React.useCallback(async () => {
    try {
      const { createdSessionId, signIn, signUp, setActive } = await startOAuthFlow({
        redirectUrl: Linking.createURL('/'),
      })

      if (createdSessionId) {
        setActive!({ session: createdSessionId })
      } else {
        // Use signIn or signUp for next steps such as MFA
      }
    } catch (err) {
      console.error('OAuth error', err)
    }
  }, [])

  return (
    <View>
      <Link href="/">
        <Text>Home</Text>
      </Link>
      <Button title="Sign in with Google" onPress={onPress} />
    </View>
  )
}
export default SignInWithOAuth

Want to learn more about using Clerk with Expo? Check out @clerk/clerk-expo.

Excited specifically about Expo Web? Check out our Expo Web support guide.

Contributor
Vaggelis Yfantis

Passkeys are now Generally Available

Category
GA
Published

Passkeys are now generally available for all Clerk users

After a thorough beta period, we're excited to announce that Passkeys are now generally available for all Clerk users. Passkeys are a simple-to-use and secure passwordless way to authenticate your users.

Passkeys are available as part of the Pro plan. Head to the Clerk Dashboard to activate Passkeys for your users or read through the Passkeys documentation to get started.

Contributors
Mary Zhong
Pantelis Eleftheriadis

Improved support for Cypress testing

Category
E2E
Published

Enhanced end-to-end testing with Clerk using Cypress

We are thrilled to announce significant enhancements to our @clerk/testing package, making it easier to use Cypress with Clerk!

@clerk/testing@1.2.0 includes the following improvements:

  • Full browser support: We have resolved existing issues with Cypress and now support all Cypress-supported browsers, including Chrome, Electron, and Firefox.
  • Testing Tokens: The testing tokens mechanism that was introduced in the Playwright integration is now available in Cypress as well. This feature allows you to bypass bot detection mechanisms effortlessly, eliminating frustrating "Bot traffic detected" errors and enabling uninterrupted testing workflows.
  • Cypress Custom Commands: We've added custom Clerk commands that you can use inside your tests. These commands, like cy.clerkSignIn() and cy.clerkSignOut(), make it easy to handle sign-in and sign-out actions within your tests without interacting with the UI.

To learn more and get detailed setup instructions, visit our Cypress documentation.

Contributor
Stefanos Anagnostou

Official SDK for Astro

Category
SDK
Published

Our community SDK is all grown up 🧑‍🚀

Astro is one of the most loved web frameworks for the past couple of years, it's a modern framework for fast content-driven websites, while also making it trivial to create dynamic web applications.

Today, we're proud to announce @clerk/astro, a new official SDK that allows developers to add authentication and authorization into their Astro application in matter of minutes.

The SDK comes fully equiped with Clerk's UI components, middleware, and low level utilities for your custom flows.

Use Clerk UI components

Clerk's pre-built UI components give you a beautiful, fully-functional user and organization management experience in minutes. Here's an example on how to use the <SignIn /> component in Astro.

src/pages/sign-in/[...signIn].astro
---
import { SignIn } from '@clerk/astro/components'
---

<SignIn path="/sign-in" />

Protect routes with Clerk Middleware

Use clerkMiddleware and the auth function to restrict logged out users from accessing the /user routes.

src/middleware.ts
import { clerkMiddleware, createRouteMatcher } from '@clerk/astro/server'

const isProtectedPage = createRouteMatcher(['/user(.*)'])

export const onRequest = clerkMiddleware((auth, context, next) => {
  if (isProtectedPage(context.request) && !auth().userId) {
    return auth().redirectToSignIn()
  }

  return next()
})

Individual page protection

If the /me page is not protected by the middleware, you can still protect the page directly. The code below uses Astro.locals.auth() in order redirect the user the sign-in page or render their userId.

src/pages/me.astro
---
const { userId, redirectToSignIn } = Astro.locals.auth()

if (!userId) {
  return redirectToSignIn()
}
---

<p>My user id is {userId}</p>

Usage with React

Astro offers a way to use React inside your Astro application. @clerk/astro takes advantage of that and exposes components, hooks, and utilities for those cases.

src/components/Header.tsx
import { SignInButton, SignedIn, SignedOut, UserButton } from '@clerk/astro/react'

export default function Header() {
  return (
    <>
      <p>My App</p>
      <SignedOut>
        <SignInButton />
      </SignedOut>
      <SignedIn>
        <UserButton />
      </SignedIn>
    </>
  )
}

This is only a quick preview of all that @clerk/astro offers.

For more information on the available API and how to get started building Astro applications with Clerk, check out our Astro Quickstart guide.

And last but not least, we would like to acknowledge and thank all of the contributors of the previous community SDK for Astro, which was a great source of inspiration for us.

Contributors
Pantelis Eleftheriadis
Robert Soriano

Remix SPA mode

Category
SDK
Published

@clerk/remix now supports Remix SPA Mode

Starting with @clerk/remix@4.2.0 our Remix SDK now supports Remix SPA mode. This means that you can now use Clerk in your Remix app without server-side rendering.

After creating a Remix app with SPA mode enabled, install the latest @clerk/remix package:

terminal
npm install @clerk/remix@latest
terminal
yarn add @clerk/remix@latest
terminal
pnpm add @clerk/remix@latest

You can then use ClerkApp inside your root route and use Clerk's control components to protect your pages. Clerk will automatically detect that your Remix app is running in SPA mode and will take care of the rest.

To read the full guide and learn more about Clerk and Remix SPA Mode, head over to the Remix SPA mode reference guide.

Contributor
Stefanos Anagnostou

Next.js Dynamic Keys

Category
SDK
Published

Keys and options passed to clerkMiddleware() at runtime are available in Clerk’s server-side helpers.

Users building a multi-tenant application might need to provide different Clerk keys depending on the incoming request. Previously, you would need to pass these keys to all of Clerk’s Next.js server-side helpers. With Dynamic Keys support, keys passed to clerkMiddleware() are made available to auth() and other server-side helpers.

middleware.ts
import { clerkMiddleware } from '@clerk/nextjs/server'

export default clerkMiddleware({
  secretKey: '<YOUR_SECRET_KEY>',
  publishableKey: '<YOUR_PUBLISHABLE_KEY>',
  signInUrl: '/my-sign-in',
  signUpUrl: '/my-sign-up',
})

export const config = {
  matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'],
}

With a centralized place for passing server-side options, implementing a multi-tenant application that requires dynamic Clerk keys should be much more straightforward. This feature is available as of @clerk/nextjs@5.2.x.

Check out the documentation for additional details and happy building!

Contributor
Laura Beatris