@better-auth/expo 1.5.0-beta.1 → 1.5.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +15 -12
- package/README.md +40 -29
- package/dist/client.d.mts +21 -0
- package/dist/client.mjs +9 -5
- package/dist/index.d.mts +7 -0
- package/package.json +6 -9
package/LICENSE.md
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
Copyright (c) 2024 - present, Bereket Engida
|
|
3
3
|
|
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
|
-
and associated documentation files (the
|
|
6
|
-
including without limitation the rights to
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
|
+
this software and associated documentation files (the “Software”), to deal in
|
|
6
|
+
the Software without restriction, including without limitation the rights to
|
|
7
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
8
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
9
|
+
subject to the following conditions:
|
|
9
10
|
|
|
10
|
-
The above copyright notice and this permission notice shall be included in all
|
|
11
|
-
substantial portions of the Software.
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
12
13
|
|
|
13
|
-
THE SOFTWARE IS PROVIDED
|
|
14
|
-
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
16
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
19
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20
|
+
DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Better Auth Expo Plugin
|
|
2
2
|
|
|
3
|
-
This plugin integrates Better Auth with Expo, allowing you to easily add
|
|
3
|
+
This plugin integrates Better Auth with Expo, allowing you to easily add
|
|
4
|
+
authentication to your Expo (React Native) applications.
|
|
5
|
+
It supports both Expo native and web apps.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
@@ -20,7 +22,8 @@ pnpm add better-auth @better-auth/expo
|
|
|
20
22
|
bun add better-auth @better-auth/expo
|
|
21
23
|
```
|
|
22
24
|
|
|
23
|
-
You will also need to install `expo-secure-store` for secure session and cookie
|
|
25
|
+
You will also need to install `expo-secure-store` for secure session and cookie
|
|
26
|
+
storage in your Expo app:
|
|
24
27
|
|
|
25
28
|
```bash
|
|
26
29
|
npm install expo-secure-store
|
|
@@ -36,24 +39,26 @@ bun add expo-secure-store
|
|
|
36
39
|
|
|
37
40
|
### Configure the Better Auth Backend
|
|
38
41
|
|
|
39
|
-
Ensure you have a Better Auth backend set up.
|
|
42
|
+
Ensure you have a Better Auth backend set up.
|
|
43
|
+
You can follow the main [Installation Guide][].
|
|
40
44
|
|
|
41
|
-
Then, add the Expo plugin to your Better Auth server configuration (e.g., in
|
|
45
|
+
Then, add the Expo plugin to your Better Auth server configuration (e.g., in
|
|
46
|
+
your `auth.ts` or `lib/auth.ts` file):
|
|
42
47
|
|
|
43
48
|
```typescript
|
|
44
49
|
// lib/auth.ts
|
|
45
|
-
import { betterAuth } from
|
|
46
|
-
import { expo } from
|
|
50
|
+
import { betterAuth } from 'better-auth';
|
|
51
|
+
import { expo } from '@better-auth/expo'; // Import the server plugin
|
|
47
52
|
|
|
48
53
|
export const auth = betterAuth({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
// ...your other Better Auth options
|
|
55
|
+
baseURL: 'http://localhost:8081', // The base URL of your application server where the routes are mounted.
|
|
56
|
+
plugins: [expo()], // Add the Expo server plugin
|
|
57
|
+
emailAndPassword: {
|
|
58
|
+
enabled: true,
|
|
59
|
+
},
|
|
60
|
+
// Add other configurations like trustedOrigins
|
|
61
|
+
trustedOrigins: ['myapp://'], // Replace "myapp" with your app's scheme
|
|
57
62
|
});
|
|
58
63
|
```
|
|
59
64
|
|
|
@@ -63,33 +68,39 @@ In your Expo app, initialize the client (e.g., in `lib/auth-client.ts`):
|
|
|
63
68
|
|
|
64
69
|
```typescript
|
|
65
70
|
// lib/auth-client.ts
|
|
66
|
-
import { createAuthClient } from
|
|
67
|
-
import { expoClient } from
|
|
68
|
-
import * as SecureStore from
|
|
71
|
+
import { createAuthClient } from 'better-auth/react';
|
|
72
|
+
import { expoClient } from '@better-auth/expo/client'; // Import the client plugin
|
|
73
|
+
import * as SecureStore from 'expo-secure-store';
|
|
69
74
|
|
|
70
75
|
export const authClient = createAuthClient({
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
baseURL: 'http://localhost:8081', // Your Better Auth backend URL
|
|
77
|
+
plugins: [
|
|
78
|
+
expoClient({
|
|
79
|
+
scheme: 'myapp', // Your app's scheme (defined in app.json)
|
|
80
|
+
storagePrefix: 'myapp', // A prefix for storage keys
|
|
81
|
+
storage: SecureStore, // Pass SecureStore for token storage
|
|
82
|
+
}),
|
|
83
|
+
],
|
|
79
84
|
});
|
|
80
85
|
|
|
81
86
|
// You can also export specific methods if you prefer:
|
|
82
87
|
// export const { signIn, signUp, useSession } = authClient;
|
|
83
88
|
```
|
|
84
|
-
|
|
89
|
+
|
|
90
|
+
Make sure your app’s scheme (e.g., “myapp”) is defined in your `app.json`.
|
|
85
91
|
|
|
86
92
|
## Documentation
|
|
87
93
|
|
|
88
|
-
For more detailed information and advanced configurations, please refer to the
|
|
94
|
+
For more detailed information and advanced configurations, please refer to the
|
|
95
|
+
documentation:
|
|
89
96
|
|
|
90
|
-
|
|
91
|
-
|
|
97
|
+
* **Main Better Auth Installation:** [Installation Guide][]
|
|
98
|
+
* **Expo Integration Guide:** [Expo Integration Guide][]
|
|
92
99
|
|
|
93
100
|
## License
|
|
94
101
|
|
|
95
102
|
MIT
|
|
103
|
+
|
|
104
|
+
[expo integration guide]: https://www.better-auth.com/docs/integrations/expo
|
|
105
|
+
|
|
106
|
+
[installation guide]: https://www.better-auth.com/docs/installation
|
package/dist/client.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FocusManager, OnlineManager } from "better-auth/client";
|
|
2
|
+
import * as expo_web_browser0 from "expo-web-browser";
|
|
2
3
|
import * as _better_fetch_fetch0 from "@better-fetch/fetch";
|
|
3
4
|
import { ClientFetchOption, ClientStore } from "@better-auth/core";
|
|
4
5
|
|
|
@@ -42,6 +43,26 @@ interface ExpoClientOptions {
|
|
|
42
43
|
*/
|
|
43
44
|
cookiePrefix?: string | string[] | undefined;
|
|
44
45
|
disableCache?: boolean | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Options to customize the Expo web browser behavior when opening authentication
|
|
48
|
+
* sessions. These are passed directly to `expo-web-browser`'s
|
|
49
|
+
* `Browser.openBrowserAsync`.
|
|
50
|
+
*
|
|
51
|
+
* For example, on iOS you can use `{ preferEphemeralSession: true }` to prevent
|
|
52
|
+
* the authentication session from sharing cookies with the user's default
|
|
53
|
+
* browser session:
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* const client = createClient({
|
|
57
|
+
* expo: {
|
|
58
|
+
* webBrowserOptions: {
|
|
59
|
+
* preferEphemeralSession: true,
|
|
60
|
+
* },
|
|
61
|
+
* },
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
webBrowserOptions?: expo_web_browser0.AuthSessionOpenOptions;
|
|
45
66
|
}
|
|
46
67
|
declare function getSetCookie(header: string, prevCookie?: string | undefined): string;
|
|
47
68
|
declare function getCookie(cookie: string): string;
|
package/dist/client.mjs
CHANGED
|
@@ -75,14 +75,18 @@ function parseSetCookieHeader(header) {
|
|
|
75
75
|
const cookieMap = /* @__PURE__ */ new Map();
|
|
76
76
|
splitSetCookieHeader(header).forEach((cookie) => {
|
|
77
77
|
const [nameValue, ...attributes] = cookie.split(";").map((p) => p.trim());
|
|
78
|
-
const [name, ...valueParts] = nameValue.split("=");
|
|
79
|
-
const
|
|
78
|
+
const [name, ...valueParts] = (nameValue || "").split("=");
|
|
79
|
+
const value = valueParts.join("=");
|
|
80
|
+
if (!name || value === void 0) return;
|
|
81
|
+
const attrObj = { value };
|
|
80
82
|
attributes.forEach((attr) => {
|
|
81
83
|
const [attrName, ...attrValueParts] = attr.split("=");
|
|
84
|
+
if (!attrName?.trim()) return;
|
|
82
85
|
const attrValue = attrValueParts.join("=");
|
|
83
|
-
|
|
86
|
+
const normalizedAttrName = attrName.trim().toLowerCase();
|
|
87
|
+
attrObj[normalizedAttrName] = attrValue;
|
|
84
88
|
});
|
|
85
|
-
cookieMap.set(name,
|
|
89
|
+
cookieMap.set(name, attrObj);
|
|
86
90
|
});
|
|
87
91
|
return cookieMap;
|
|
88
92
|
}
|
|
@@ -275,7 +279,7 @@ const expoClient = (opts) => {
|
|
|
275
279
|
Browser.dismissAuthSession();
|
|
276
280
|
} catch {}
|
|
277
281
|
const proxyURL = `${context.request.baseURL}/expo-authorization-proxy?authorizationURL=${encodeURIComponent(signInURL)}`;
|
|
278
|
-
const result = await Browser.openAuthSessionAsync(proxyURL, to);
|
|
282
|
+
const result = await Browser.openAuthSessionAsync(proxyURL, to, opts?.webBrowserOptions);
|
|
279
283
|
if (result.type !== "success") return;
|
|
280
284
|
const url = new URL(result.url);
|
|
281
285
|
const cookie = String(url.searchParams.get("cookie"));
|
package/dist/index.d.mts
CHANGED
|
@@ -10,6 +10,13 @@ interface ExpoOptions {
|
|
|
10
10
|
*/
|
|
11
11
|
disableOriginOverride?: boolean | undefined;
|
|
12
12
|
}
|
|
13
|
+
declare module "@better-auth/core" {
|
|
14
|
+
interface BetterAuthPluginRegistry<Auth, Context> {
|
|
15
|
+
expo: {
|
|
16
|
+
creator: typeof expo;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
13
20
|
declare const expo: (options?: ExpoOptions | undefined) => {
|
|
14
21
|
id: "expo";
|
|
15
22
|
init: (ctx: better_auth0.AuthContext) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/expo",
|
|
3
|
-
"version": "1.5.0-beta.
|
|
3
|
+
"version": "1.5.0-beta.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Better Auth integration for Expo and React Native applications.",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -61,16 +61,16 @@
|
|
|
61
61
|
"expo-web-browser": "~14.2.0",
|
|
62
62
|
"react-native": "~0.80.2",
|
|
63
63
|
"tsdown": "^0.17.2",
|
|
64
|
-
"@better-auth/core": "1.5.0-beta.
|
|
65
|
-
"better-auth": "1.5.0-beta.
|
|
64
|
+
"@better-auth/core": "1.5.0-beta.3",
|
|
65
|
+
"better-auth": "1.5.0-beta.3"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"expo-constants": ">=17.0.0",
|
|
69
69
|
"expo-linking": ">=7.0.0",
|
|
70
70
|
"expo-network": "^8.0.7",
|
|
71
71
|
"expo-web-browser": ">=14.0.0",
|
|
72
|
-
"better-auth": "1.5.0-beta.
|
|
73
|
-
"
|
|
72
|
+
"@better-auth/core": "1.5.0-beta.3",
|
|
73
|
+
"better-auth": "1.5.0-beta.3"
|
|
74
74
|
},
|
|
75
75
|
"peerDependenciesMeta": {
|
|
76
76
|
"expo-constants": {
|
|
@@ -79,16 +79,13 @@
|
|
|
79
79
|
"expo-linking": {
|
|
80
80
|
"optional": true
|
|
81
81
|
},
|
|
82
|
-
"expo-network": {
|
|
83
|
-
"optional": true
|
|
84
|
-
},
|
|
85
82
|
"expo-web-browser": {
|
|
86
83
|
"optional": true
|
|
87
84
|
}
|
|
88
85
|
},
|
|
89
86
|
"dependencies": {
|
|
90
87
|
"@better-fetch/fetch": "1.1.21",
|
|
91
|
-
"better-call": "1.1.
|
|
88
|
+
"better-call": "1.1.8",
|
|
92
89
|
"zod": "^4.1.12"
|
|
93
90
|
},
|
|
94
91
|
"files": [
|