@payez/next-mvp 3.9.0 → 3.9.1
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.
|
@@ -4,11 +4,8 @@
|
|
|
4
4
|
* Drop-in replacement for next-auth/react hooks and functions.
|
|
5
5
|
* Import from '@payez/next-mvp/client/better-auth-client'.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* signIn('google') → authClient.signIn.social({ provider: 'google' })
|
|
10
|
-
* signIn('credentials', {...}) → authClient.signIn.email({...})
|
|
11
|
-
* signOut() → authClient.signOut()
|
|
7
|
+
* Includes useSessionCompat() — returns NextAuth-shaped { data, status }
|
|
8
|
+
* so existing components don't need destructure pattern changes.
|
|
12
9
|
*/
|
|
13
10
|
export declare const authClient: {
|
|
14
11
|
signIn: {
|
|
@@ -959,3 +956,65 @@ export declare const useSession: () => {
|
|
|
959
956
|
code?: string | undefined;
|
|
960
957
|
message?: string | undefined;
|
|
961
958
|
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
959
|
+
/**
|
|
960
|
+
* NextAuth-compatible useSession wrapper.
|
|
961
|
+
*
|
|
962
|
+
* Maps Better Auth's { data, error, isPending } to NextAuth's { data, status, update }.
|
|
963
|
+
* Drop-in replacement — no destructure changes needed in consuming components.
|
|
964
|
+
*/
|
|
965
|
+
export declare function useSessionCompat(): {
|
|
966
|
+
data: {
|
|
967
|
+
user: import("better-auth/react").StripEmptyObjects<{
|
|
968
|
+
id: string;
|
|
969
|
+
createdAt: Date;
|
|
970
|
+
updatedAt: Date;
|
|
971
|
+
email: string;
|
|
972
|
+
emailVerified: boolean;
|
|
973
|
+
name: string;
|
|
974
|
+
image?: string | null | undefined;
|
|
975
|
+
}>;
|
|
976
|
+
expires: string;
|
|
977
|
+
session: import("better-auth/react").StripEmptyObjects<{
|
|
978
|
+
id: string;
|
|
979
|
+
createdAt: Date;
|
|
980
|
+
updatedAt: Date;
|
|
981
|
+
userId: string;
|
|
982
|
+
expiresAt: Date;
|
|
983
|
+
token: string;
|
|
984
|
+
ipAddress?: string | null | undefined;
|
|
985
|
+
userAgent?: string | null | undefined;
|
|
986
|
+
}>;
|
|
987
|
+
} | null;
|
|
988
|
+
status: "loading" | "authenticated" | "unauthenticated";
|
|
989
|
+
update: () => Promise<{
|
|
990
|
+
user: import("better-auth/react").StripEmptyObjects<{
|
|
991
|
+
id: string;
|
|
992
|
+
createdAt: Date;
|
|
993
|
+
updatedAt: Date;
|
|
994
|
+
email: string;
|
|
995
|
+
emailVerified: boolean;
|
|
996
|
+
name: string;
|
|
997
|
+
image?: string | null | undefined;
|
|
998
|
+
}>;
|
|
999
|
+
expires: string;
|
|
1000
|
+
session: import("better-auth/react").StripEmptyObjects<{
|
|
1001
|
+
id: string;
|
|
1002
|
+
createdAt: Date;
|
|
1003
|
+
updatedAt: Date;
|
|
1004
|
+
userId: string;
|
|
1005
|
+
expiresAt: Date;
|
|
1006
|
+
token: string;
|
|
1007
|
+
ipAddress?: string | null | undefined;
|
|
1008
|
+
userAgent?: string | null | undefined;
|
|
1009
|
+
}>;
|
|
1010
|
+
} | null>;
|
|
1011
|
+
};
|
|
1012
|
+
/**
|
|
1013
|
+
* NextAuth-compatible signOut wrapper.
|
|
1014
|
+
*
|
|
1015
|
+
* Maps NextAuth signOut({ redirect, callbackUrl }) to Better Auth.
|
|
1016
|
+
*/
|
|
1017
|
+
export declare function signOutCompat(options?: {
|
|
1018
|
+
redirect?: boolean;
|
|
1019
|
+
callbackUrl?: string;
|
|
1020
|
+
}): Promise<void>;
|
|
@@ -5,17 +5,64 @@
|
|
|
5
5
|
* Drop-in replacement for next-auth/react hooks and functions.
|
|
6
6
|
* Import from '@payez/next-mvp/client/better-auth-client'.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* signIn('google') → authClient.signIn.social({ provider: 'google' })
|
|
11
|
-
* signIn('credentials', {...}) → authClient.signIn.email({...})
|
|
12
|
-
* signOut() → authClient.signOut()
|
|
8
|
+
* Includes useSessionCompat() — returns NextAuth-shaped { data, status }
|
|
9
|
+
* so existing components don't need destructure pattern changes.
|
|
13
10
|
*/
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.signOut = exports.signIn = exports.useSession = exports.authClient = void 0;
|
|
13
|
+
exports.useSessionCompat = useSessionCompat;
|
|
14
|
+
exports.signOutCompat = signOutCompat;
|
|
16
15
|
const react_1 = require("better-auth/react");
|
|
16
|
+
const react_2 = require("react");
|
|
17
17
|
exports.authClient = (0, react_1.createAuthClient)({
|
|
18
|
-
// baseURL
|
|
18
|
+
// baseURL derived from BETTER_AUTH_URL or window.location.origin
|
|
19
19
|
});
|
|
20
|
-
// Convenience exports
|
|
20
|
+
// Convenience exports
|
|
21
21
|
exports.useSession = exports.authClient.useSession, exports.signIn = exports.authClient.signIn, exports.signOut = exports.authClient.signOut;
|
|
22
|
+
/**
|
|
23
|
+
* NextAuth-compatible useSession wrapper.
|
|
24
|
+
*
|
|
25
|
+
* Maps Better Auth's { data, error, isPending } to NextAuth's { data, status, update }.
|
|
26
|
+
* Drop-in replacement — no destructure changes needed in consuming components.
|
|
27
|
+
*/
|
|
28
|
+
function useSessionCompat() {
|
|
29
|
+
const baSession = exports.authClient.useSession();
|
|
30
|
+
const status = (0, react_2.useMemo)(() => {
|
|
31
|
+
if (baSession.isPending)
|
|
32
|
+
return 'loading';
|
|
33
|
+
if (baSession.data)
|
|
34
|
+
return 'authenticated';
|
|
35
|
+
return 'unauthenticated';
|
|
36
|
+
}, [baSession.isPending, baSession.data]);
|
|
37
|
+
// Map Better Auth session shape to NextAuth session shape
|
|
38
|
+
const data = (0, react_2.useMemo)(() => {
|
|
39
|
+
if (!baSession.data)
|
|
40
|
+
return null;
|
|
41
|
+
return {
|
|
42
|
+
...baSession.data,
|
|
43
|
+
user: baSession.data.user,
|
|
44
|
+
expires: '', // Better Auth handles expiry differently
|
|
45
|
+
};
|
|
46
|
+
}, [baSession.data]);
|
|
47
|
+
return {
|
|
48
|
+
data,
|
|
49
|
+
status,
|
|
50
|
+
update: async () => {
|
|
51
|
+
// Better Auth doesn't have a direct "refresh session" call.
|
|
52
|
+
// Force refetch by invalidating the query.
|
|
53
|
+
// TODO: Wire to proper session refresh when available.
|
|
54
|
+
return data;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* NextAuth-compatible signOut wrapper.
|
|
60
|
+
*
|
|
61
|
+
* Maps NextAuth signOut({ redirect, callbackUrl }) to Better Auth.
|
|
62
|
+
*/
|
|
63
|
+
async function signOutCompat(options) {
|
|
64
|
+
await exports.authClient.signOut();
|
|
65
|
+
if (options?.redirect !== false && options?.callbackUrl) {
|
|
66
|
+
window.location.href = options.callbackUrl;
|
|
67
|
+
}
|
|
68
|
+
}
|
package/package.json
CHANGED
|
@@ -4,18 +4,65 @@
|
|
|
4
4
|
* Drop-in replacement for next-auth/react hooks and functions.
|
|
5
5
|
* Import from '@payez/next-mvp/client/better-auth-client'.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* signIn('google') → authClient.signIn.social({ provider: 'google' })
|
|
10
|
-
* signIn('credentials', {...}) → authClient.signIn.email({...})
|
|
11
|
-
* signOut() → authClient.signOut()
|
|
7
|
+
* Includes useSessionCompat() — returns NextAuth-shaped { data, status }
|
|
8
|
+
* so existing components don't need destructure pattern changes.
|
|
12
9
|
*/
|
|
13
10
|
|
|
14
11
|
import { createAuthClient } from 'better-auth/react';
|
|
12
|
+
import { useMemo } from 'react';
|
|
15
13
|
|
|
16
14
|
export const authClient = createAuthClient({
|
|
17
|
-
// baseURL
|
|
15
|
+
// baseURL derived from BETTER_AUTH_URL or window.location.origin
|
|
18
16
|
});
|
|
19
17
|
|
|
20
|
-
// Convenience exports
|
|
18
|
+
// Convenience exports
|
|
21
19
|
export const { useSession, signIn, signOut } = authClient;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* NextAuth-compatible useSession wrapper.
|
|
23
|
+
*
|
|
24
|
+
* Maps Better Auth's { data, error, isPending } to NextAuth's { data, status, update }.
|
|
25
|
+
* Drop-in replacement — no destructure changes needed in consuming components.
|
|
26
|
+
*/
|
|
27
|
+
export function useSessionCompat() {
|
|
28
|
+
const baSession = authClient.useSession();
|
|
29
|
+
|
|
30
|
+
const status = useMemo(() => {
|
|
31
|
+
if (baSession.isPending) return 'loading' as const;
|
|
32
|
+
if (baSession.data) return 'authenticated' as const;
|
|
33
|
+
return 'unauthenticated' as const;
|
|
34
|
+
}, [baSession.isPending, baSession.data]);
|
|
35
|
+
|
|
36
|
+
// Map Better Auth session shape to NextAuth session shape
|
|
37
|
+
const data = useMemo(() => {
|
|
38
|
+
if (!baSession.data) return null;
|
|
39
|
+
return {
|
|
40
|
+
...baSession.data,
|
|
41
|
+
user: baSession.data.user,
|
|
42
|
+
expires: '', // Better Auth handles expiry differently
|
|
43
|
+
};
|
|
44
|
+
}, [baSession.data]);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
data,
|
|
48
|
+
status,
|
|
49
|
+
update: async () => {
|
|
50
|
+
// Better Auth doesn't have a direct "refresh session" call.
|
|
51
|
+
// Force refetch by invalidating the query.
|
|
52
|
+
// TODO: Wire to proper session refresh when available.
|
|
53
|
+
return data;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* NextAuth-compatible signOut wrapper.
|
|
60
|
+
*
|
|
61
|
+
* Maps NextAuth signOut({ redirect, callbackUrl }) to Better Auth.
|
|
62
|
+
*/
|
|
63
|
+
export async function signOutCompat(options?: { redirect?: boolean; callbackUrl?: string }) {
|
|
64
|
+
await authClient.signOut();
|
|
65
|
+
if (options?.redirect !== false && options?.callbackUrl) {
|
|
66
|
+
window.location.href = options.callbackUrl;
|
|
67
|
+
}
|
|
68
|
+
}
|