Skip to content

feat(clerk-expo): Improved offline support for Expo - #4604

Merged
anagstef merged 50 commits into
mainfrom
stefanos/eco-232-find-a-solution-for-isloaded-on-expo
Dec 12, 2024
Merged

anagstef merged 50 commits into
mainfrom
stefanos/eco-232-find-a-solution-for-isloaded-on-expo

Conversation

@anagstef

@anagstef anagstef commented Nov 19, 2024 •

Copy link
Copy Markdown
Contributor

Description

We're introducing improved offline support for the @clerk/clerk-expo package to enhance reliability and user experience. This new improvement allows apps to bootstrap without an internet connection by using cached Clerk resources, ensuring quick initialization.

It solves issues such as the following:

  • Faster resolution of the isLoaded property and the ClerkLoaded component, with only a single network fetch attempt, and if it fails, it falls back to the cached resources.
  • The getToken function of useAuth hook now returns a cached token if network errors occur.
  • Developers can now catch and handle network errors gracefully in their custom flows, as the errors are no longer muted.

How to use it:

  1. Install the expo-secure-store package in your project by running:

    npm i expo-secure-store
  2. Use import { secureStore } from "@clerk/clerk-expo/secure-store" to import our implementation of the SecureStore API.

  3. Pass the secureStore in the __experimental_resourceCache property of the ClerkProvider to enable offline support.

import { ClerkProvider, ClerkLoaded } from '@clerk/clerk-expo'
import { Slot } from 'expo-router'
import { tokenCache } from '../token-cache'
import { secureStore } from '@clerk/clerk-expo/secure-store'

export default function RootLayout() {
  const publishableKey = process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY!

  if (!publishableKey) {
    throw new Error('Add EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY to your .env file')
  }

  return (
    <ClerkProvider 
        publishableKey={publishableKey}
        tokenCache={tokenCache}
        __experimental_resourceCache={secureStore}
    >
      <ClerkLoaded>
        <Slot />
      </ClerkLoaded>
    </ClerkProvider>
  )
}

relates to #3563

Checklist

  • pnpm test runs as expected.
  • pnpm 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:

@anagstef anagstef self-assigned this Nov 19, 2024
@changeset-bot

changeset-bot Bot commented Nov 19, 2024 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4901cdc

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

This PR includes changesets to release 23 packages
Name Type
@clerk/shared Patch
@clerk/clerk-expo Minor
@clerk/clerk-js Patch
@clerk/clerk-react Patch
@clerk/types Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/chrome-extension Patch
@clerk/elements Patch
@clerk/expo-passkeys Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/clerk-sdk-node Patch
@clerk/tanstack-start Patch
@clerk/testing Patch
@clerk/ui Patch
@clerk/vue Patch
@clerk/localizations Patch
@clerk/themes 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

@anagstef anagstef changed the title fix(expo): wip fix(expo): Try caching the environment/client values Nov 19, 2024
@anagstef

Copy link
Copy Markdown
Contributor Author

!snapshot

@anagstef
anagstef force-pushed the stefanos/eco-232-find-a-solution-for-isloaded-on-expo branch from b45c540 to 3082f30 Compare November 19, 2024 15:38
@anagstef

Copy link
Copy Markdown
Contributor Author

!snapshot

@clerk-cookie

Copy link
Copy Markdown
Collaborator

Hey @anagstef - the snapshot version command generated the following package versions:

Package Version
@clerk/astro 1.4.14-snapshot.v20241119154041
@clerk/backend 1.17.1-snapshot.v20241119154041
@clerk/chrome-extension 1.3.38-snapshot.v20241119154041
@clerk/clerk-js 5.34.4-snapshot.v20241119154041
@clerk/elements 0.19.5-snapshot.v20241119154041
@clerk/clerk-expo 2.3.7-snapshot.v20241119154041
@clerk/expo-passkeys 0.0.7-snapshot.v20241119154041
@clerk/express 1.3.16-snapshot.v20241119154041
@clerk/fastify 2.0.18-snapshot.v20241119154041
@clerk/localizations 3.6.5-snapshot.v20241119154041
@clerk/nextjs 6.4.1-snapshot.v20241119154041
@clerk/nuxt 0.0.2-snapshot.v20241119154041
@clerk/clerk-react 5.16.1-snapshot.v20241119154041
@clerk/remix 4.2.54-snapshot.v20241119154041
@clerk/clerk-sdk-node 5.0.67-snapshot.v20241119154041
@clerk/shared 2.15.1-snapshot.v20241119154041
@clerk/tanstack-start 0.5.1-snapshot.v20241119154041
@clerk/testing 1.3.28-snapshot.v20241119154041
@clerk/themes 2.1.46-snapshot.v20241119154041
@clerk/types 4.34.1-snapshot.v20241119154041
@clerk/ui 0.1.22-snapshot.v20241119154041
@clerk/vue 0.0.6-snapshot.v20241119154041

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/astro

npm i @clerk/astro@1.4.14-snapshot.v20241119154041 --save-exact

@clerk/backend

npm i @clerk/backend@1.17.1-snapshot.v20241119154041 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@1.3.38-snapshot.v20241119154041 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.34.4-snapshot.v20241119154041 --save-exact

@clerk/elements

npm i @clerk/elements@0.19.5-snapshot.v20241119154041 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@2.3.7-snapshot.v20241119154041 --save-exact

@clerk/expo-passkeys

npm i @clerk/expo-passkeys@0.0.7-snapshot.v20241119154041 --save-exact

@clerk/express

npm i @clerk/express@1.3.16-snapshot.v20241119154041 --save-exact

@clerk/fastify

npm i @clerk/fastify@2.0.18-snapshot.v20241119154041 --save-exact

@clerk/localizations

npm i @clerk/localizations@3.6.5-snapshot.v20241119154041 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@6.4.1-snapshot.v20241119154041 --save-exact

@clerk/nuxt

npm i @clerk/nuxt@0.0.2-snapshot.v20241119154041 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.16.1-snapshot.v20241119154041 --save-exact

@clerk/remix

npm i @clerk/remix@4.2.54-snapshot.v20241119154041 --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@5.0.67-snapshot.v20241119154041 --save-exact

@clerk/shared

npm i @clerk/shared@2.15.1-snapshot.v20241119154041 --save-exact

@clerk/tanstack-start

npm i @clerk/tanstack-start@0.5.1-snapshot.v20241119154041 --save-exact

@clerk/testing

npm i @clerk/testing@1.3.28-snapshot.v20241119154041 --save-exact

@clerk/themes

npm i @clerk/themes@2.1.46-snapshot.v20241119154041 --save-exact

@clerk/types

npm i @clerk/types@4.34.1-snapshot.v20241119154041 --save-exact

@clerk/ui

npm i @clerk/ui@0.1.22-snapshot.v20241119154041 --save-exact

@clerk/vue

npm i @clerk/vue@0.0.6-snapshot.v20241119154041 --save-exact

@vercel

vercel Bot commented Nov 22, 2024 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 12, 2024 6:58pm

@anagstef
anagstef force-pushed the stefanos/eco-232-find-a-solution-for-isloaded-on-expo branch from 99c1caf to d83a803 Compare November 22, 2024 14:10
@anagstef

Copy link
Copy Markdown
Contributor Author

!snapshot

@clerk-cookie

Copy link
Copy Markdown
Collaborator

Hey @anagstef - the snapshot version command generated the following package versions:

Package Version
@clerk/astro 1.4.15-snapshot.v20241122141417
@clerk/backend 1.17.2-snapshot.v20241122141417
@clerk/chrome-extension 1.3.40-snapshot.v20241122141417
@clerk/clerk-js 5.34.6-snapshot.v20241122141417
@clerk/elements 0.19.6-snapshot.v20241122141417
@clerk/clerk-expo 2.3.9-snapshot.v20241122141417
@clerk/expo-passkeys 0.0.8-snapshot.v20241122141417
@clerk/express 1.3.17-snapshot.v20241122141417
@clerk/fastify 2.0.19-snapshot.v20241122141417
@clerk/localizations 3.6.6-snapshot.v20241122141417
@clerk/nextjs 6.4.2-snapshot.v20241122141417
@clerk/nuxt 0.0.3-snapshot.v20241122141417
@clerk/clerk-react 5.16.2-snapshot.v20241122141417
@clerk/remix 4.2.55-snapshot.v20241122141417
@clerk/clerk-sdk-node 5.0.68-snapshot.v20241122141417
@clerk/shared 2.16.1-snapshot.v20241122141417
@clerk/tanstack-start 0.5.2-snapshot.v20241122141417
@clerk/testing 1.3.29-snapshot.v20241122141417
@clerk/themes 2.1.47-snapshot.v20241122141417
@clerk/types 4.34.2-snapshot.v20241122141417
@clerk/ui 0.1.23-snapshot.v20241122141417
@clerk/vue 0.0.7-snapshot.v20241122141417

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/astro

npm i @clerk/astro@1.4.15-snapshot.v20241122141417 --save-exact

@clerk/backend

npm i @clerk/backend@1.17.2-snapshot.v20241122141417 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@1.3.40-snapshot.v20241122141417 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.34.6-snapshot.v20241122141417 --save-exact

@clerk/elements

npm i @clerk/elements@0.19.6-snapshot.v20241122141417 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@2.3.9-snapshot.v20241122141417 --save-exact

@clerk/expo-passkeys

npm i @clerk/expo-passkeys@0.0.8-snapshot.v20241122141417 --save-exact

@clerk/express

npm i @clerk/express@1.3.17-snapshot.v20241122141417 --save-exact

@clerk/fastify

npm i @clerk/fastify@2.0.19-snapshot.v20241122141417 --save-exact

@clerk/localizations

npm i @clerk/localizations@3.6.6-snapshot.v20241122141417 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@6.4.2-snapshot.v20241122141417 --save-exact

@clerk/nuxt

npm i @clerk/nuxt@0.0.3-snapshot.v20241122141417 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.16.2-snapshot.v20241122141417 --save-exact

@clerk/remix

npm i @clerk/remix@4.2.55-snapshot.v20241122141417 --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@5.0.68-snapshot.v20241122141417 --save-exact

@clerk/shared

npm i @clerk/shared@2.16.1-snapshot.v20241122141417 --save-exact

@clerk/tanstack-start

npm i @clerk/tanstack-start@0.5.2-snapshot.v20241122141417 --save-exact

@clerk/testing

npm i @clerk/testing@1.3.29-snapshot.v20241122141417 --save-exact

@clerk/themes

npm i @clerk/themes@2.1.47-snapshot.v20241122141417 --save-exact

@clerk/types

npm i @clerk/types@4.34.2-snapshot.v20241122141417 --save-exact

@clerk/ui

npm i @clerk/ui@0.1.23-snapshot.v20241122141417 --save-exact

@clerk/vue

npm i @clerk/vue@0.0.7-snapshot.v20241122141417 --save-exact

@wobsoriano wobsoriano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks great!

@panteliselef panteliselef left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

This branch was successfully deployed

1 active deployment
Preview — 4901cdc3 Deployed Dec 12, 2024 by vercel[bot]
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.

8 participants