Skip to content

Commit 94592eb

Browse files
committed
fix(react-native): storage key per publishable key — was shared across all apps (@authon/react-native@0.3.5)
1 parent 2509486 commit 94592eb

4 files changed

Lines changed: 19 additions & 15 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Official SDKs for [Authon](https://authon.dev) — a modern authentication platf
1919
| [`@authon/nuxt`](./packages/nuxt) | 0.3.3 | Auto-imported composables and middleware for Nuxt 3 | [npm](https://www.npmjs.com/package/@authon/nuxt) |
2020
| [`@authon/svelte`](./packages/svelte) | 0.3.3 | Stores and components for Svelte | [npm](https://www.npmjs.com/package/@authon/svelte) |
2121
| [`@authon/angular`](./packages/angular) | 0.3.3 | Service, guard, and components for Angular | [npm](https://www.npmjs.com/package/@authon/angular) |
22-
| [`@authon/react-native`](./packages/react-native) | 0.3.4 | Mobile authentication for React Native | [npm](https://www.npmjs.com/package/@authon/react-native) |
22+
| [`@authon/react-native`](./packages/react-native) | 0.3.5 | Mobile authentication for React Native | [npm](https://www.npmjs.com/package/@authon/react-native) |
2323
| [`@authon/create-app`](./packages/create-authon-app) | 0.1.0 | CLI scaffolding tool — create new projects with Authon pre-configured | [npm](https://www.npmjs.com/package/@authon/create-app) |
2424

2525
## Features

packages/react-native/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@authon/react-native",
3-
"version": "0.3.4",
3+
"version": "0.3.5",
44
"description": "Authon React Native SDK — mobile authentication",
55
"type": "module",
66
"main": "./dist/index.cjs",

packages/react-native/src/client.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ interface ProvidersResponse {
3636

3737
type OAuthPollResponse = OAuthCompletedResponse | OAuthErrorResponse;
3838

39-
const STORAGE_KEY = 'authon-tokens';
39+
function getStorageKey(publishableKey: string): string {
40+
return `authon_session_${publishableKey.slice(0, 16)}`;
41+
}
4042

4143
export class AuthonMobileClient {
4244
private apiUrl: string;
4345
private publishableKey: string;
46+
private storageKey: string;
4447
private tokens: TokenPair | null = null;
4548
private user: AuthonUser | null = null;
4649
private storage: TokenStorage | null = null;
@@ -55,6 +58,7 @@ export class AuthonMobileClient {
5558
constructor(config: AuthonReactNativeConfig) {
5659
this.publishableKey = config.publishableKey;
5760
this.apiUrl = (config.apiUrl || DEFAULT_API_URL).replace(/\/$/, '');
61+
this.storageKey = getStorageKey(config.publishableKey);
5862
}
5963

6064
setStorage(storage: TokenStorage) {
@@ -66,7 +70,7 @@ export class AuthonMobileClient {
6670
async initialize(): Promise<TokenPair | null> {
6771
if (!this.storage) return null;
6872

69-
const stored = await this.storage.getItem(STORAGE_KEY);
73+
const stored = await this.storage.getItem(this.storageKey);
7074
if (!stored) return null;
7175

7276
try {
@@ -79,7 +83,7 @@ export class AuthonMobileClient {
7983
// Try refreshing
8084
return await this.refreshToken(tokens.refreshToken);
8185
} catch {
82-
await this.storage.removeItem(STORAGE_KEY);
86+
await this.storage.removeItem(this.storageKey);
8387
return null;
8488
}
8589
}
@@ -430,7 +434,7 @@ export class AuthonMobileClient {
430434
this.user = null;
431435
this.clearRefreshTimer();
432436
if (this.storage) {
433-
this.storage.removeItem(STORAGE_KEY).catch(() => {});
437+
this.storage.removeItem(this.storageKey).catch(() => {});
434438
}
435439
}
436440

@@ -452,7 +456,7 @@ export class AuthonMobileClient {
452456

453457
private async persistTokens(): Promise<void> {
454458
if (this.storage && this.tokens) {
455-
await this.storage.setItem(STORAGE_KEY, JSON.stringify(this.tokens));
459+
await this.storage.setItem(this.storageKey, JSON.stringify(this.tokens));
456460
}
457461
}
458462

pnpm-lock.yaml

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)