@better-auth/expo 1.4.6-beta.3 → 1.4.6-beta.6

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.
@@ -0,0 +1,49 @@
1
+ import * as _better_fetch_fetch15 from "@better-fetch/fetch";
2
+
3
+ //#region src/plugins/last-login-method.d.ts
4
+ interface LastLoginMethodClientConfig {
5
+ storage: {
6
+ setItem: (key: string, value: string) => any;
7
+ getItem: (key: string) => string | null;
8
+ deleteItemAsync: (key: string) => Promise<void>;
9
+ };
10
+ /**
11
+ * Prefix for local storage keys (e.g., "my-app_last_login_method")
12
+ * @default "better-auth"
13
+ */
14
+ storagePrefix?: string | undefined;
15
+ /**
16
+ * Custom resolve method for retrieving the last login method
17
+ */
18
+ customResolveMethod?: ((url: string | URL) => Promise<string | undefined | null> | string | undefined | null) | undefined;
19
+ }
20
+ declare const lastLoginMethodClient: (config: LastLoginMethodClientConfig) => {
21
+ id: "last-login-method-expo";
22
+ fetchPlugins: {
23
+ id: string;
24
+ name: string;
25
+ hooks: {
26
+ onResponse: (ctx: _better_fetch_fetch15.ResponseContext) => Promise<void>;
27
+ };
28
+ }[];
29
+ getActions(): {
30
+ /**
31
+ * Get the last used login method from storage
32
+ *
33
+ * @returns The last used login method or null if not found
34
+ */
35
+ getLastUsedLoginMethod: () => string | null;
36
+ /**
37
+ * Clear the last used login method from storage
38
+ */
39
+ clearLastUsedLoginMethod: () => Promise<void>;
40
+ /**
41
+ * Check if a specific login method was the last used
42
+ * @param method The method to check
43
+ * @returns True if the method was the last used, false otherwise
44
+ */
45
+ isLastUsedLoginMethod: (method: string) => boolean;
46
+ };
47
+ };
48
+ //#endregion
49
+ export { LastLoginMethodClientConfig, lastLoginMethodClient };
@@ -0,0 +1,46 @@
1
+ //#region src/plugins/last-login-method.ts
2
+ const paths = [
3
+ "/callback/",
4
+ "/oauth2/callback/",
5
+ "/sign-in/email",
6
+ "/sign-up/email"
7
+ ];
8
+ const defaultResolveMethod = (url) => {
9
+ const { pathname } = new URL(url.toString(), "http://localhost");
10
+ if (paths.some((p) => pathname.includes(p))) return pathname.split("/").pop();
11
+ if (pathname.includes("siwe")) return "siwe";
12
+ if (pathname.includes("/passkey/verify-authentication")) return "passkey";
13
+ };
14
+ const lastLoginMethodClient = (config) => {
15
+ const resolveMethod = config.customResolveMethod || defaultResolveMethod;
16
+ const lastLoginMethodName = `${config.storagePrefix || "better-auth"}_last_login_method`;
17
+ const storage = config.storage;
18
+ return {
19
+ id: "last-login-method-expo",
20
+ fetchPlugins: [{
21
+ id: "last-login-method-expo",
22
+ name: "Last Login Method",
23
+ hooks: { onResponse: async (ctx) => {
24
+ const lastMethod = await resolveMethod(ctx.request.url);
25
+ if (!lastMethod) return;
26
+ await storage.setItem(lastLoginMethodName, lastMethod);
27
+ } }
28
+ }],
29
+ getActions() {
30
+ return {
31
+ getLastUsedLoginMethod: () => {
32
+ return storage.getItem(lastLoginMethodName);
33
+ },
34
+ clearLastUsedLoginMethod: async () => {
35
+ await storage.deleteItemAsync(lastLoginMethodName);
36
+ },
37
+ isLastUsedLoginMethod: (method) => {
38
+ return storage.getItem(lastLoginMethodName) === method;
39
+ }
40
+ };
41
+ }
42
+ };
43
+ };
44
+
45
+ //#endregion
46
+ export { lastLoginMethodClient };
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@better-auth/expo",
3
- "version": "1.4.6-beta.3",
3
+ "version": "1.4.6-beta.6",
4
4
  "type": "module",
5
5
  "description": "Better Auth integration for Expo and React Native applications.",
6
6
  "main": "dist/index.mjs",
7
7
  "module": "dist/index.mjs",
8
+ "types": "dist/index.d.mts",
8
9
  "repository": {
9
10
  "type": "git",
10
- "url": "https://github.com/better-auth/better-auth",
11
+ "url": "git+https://github.com/better-auth/better-auth.git",
11
12
  "directory": "packages/expo"
12
13
  },
13
14
  "homepage": "https://www.better-auth.com/docs/integrations/expo",
@@ -21,6 +22,11 @@
21
22
  "dev-source": "./src/client.ts",
22
23
  "types": "./dist/client.d.mts",
23
24
  "default": "./dist/client.mjs"
25
+ },
26
+ "./plugins": {
27
+ "dev-source": "./src/plugins/index.ts",
28
+ "types": "./dist/plugins/index.d.mts",
29
+ "default": "./dist/plugins/index.mjs"
24
30
  }
25
31
  },
26
32
  "typesVersions": {
@@ -30,6 +36,9 @@
30
36
  ],
31
37
  "client": [
32
38
  "./dist/client.d.mts"
39
+ ],
40
+ "plugins": [
41
+ "./dist/plugins/index.d.mts"
33
42
  ]
34
43
  }
35
44
  },
@@ -54,16 +63,16 @@
54
63
  "expo-web-browser": "~14.2.0",
55
64
  "react-native": "~0.80.2",
56
65
  "tsdown": "^0.17.0",
57
- "@better-auth/core": "1.4.6-beta.3",
58
- "better-auth": "1.4.6-beta.3"
66
+ "@better-auth/core": "1.4.6-beta.6",
67
+ "better-auth": "1.4.6-beta.6"
59
68
  },
60
69
  "peerDependencies": {
61
70
  "expo-constants": ">=17.0.0",
62
71
  "expo-linking": ">=7.0.0",
63
72
  "expo-network": "^8.0.7",
64
73
  "expo-web-browser": ">=14.0.0",
65
- "better-auth": "1.4.6-beta.3",
66
- "@better-auth/core": "1.4.6-beta.3"
74
+ "@better-auth/core": "1.4.6-beta.6",
75
+ "better-auth": "1.4.6-beta.6"
67
76
  },
68
77
  "peerDependenciesMeta": {
69
78
  "expo-constants": {
@@ -81,7 +90,7 @@
81
90
  },
82
91
  "dependencies": {
83
92
  "@better-fetch/fetch": "1.1.18",
84
- "better-call": "1.1.4",
93
+ "better-call": "1.1.5",
85
94
  "zod": "^4.1.12"
86
95
  },
87
96
  "files": [
@@ -89,6 +98,7 @@
89
98
  ],
90
99
  "scripts": {
91
100
  "test": "vitest",
101
+ "coverage": "vitest run --coverage",
92
102
  "lint:package": "publint run --strict",
93
103
  "build": "tsdown",
94
104
  "dev": "tsdown --watch",