@inflector/aura 0.1.9 → 0.1.10
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/dist/auth.d.ts +7 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +34 -8
- package/package.json +1 -1
package/dist/auth.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
type SessionEvent = "login" | "logout" | "change";
|
|
2
|
+
interface SessionEventsType {
|
|
3
|
+
on(event: SessionEvent, callback: () => void): () => void;
|
|
4
|
+
emit(event: SessionEvent): void;
|
|
5
|
+
}
|
|
6
|
+
export declare const SessionEvents: SessionEventsType;
|
|
1
7
|
export declare const AuraAuth: (url: string, workspace: string) => {
|
|
2
8
|
Logout: <FetchOptions extends import("better-auth").ClientFetchOption<never, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0?: import("better-auth").Prettify<{
|
|
3
9
|
query?: Record<string, any> | undefined;
|
|
@@ -1232,4 +1238,5 @@ export declare const AuraAuth: (url: string, workspace: string) => {
|
|
|
1232
1238
|
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
1233
1239
|
};
|
|
1234
1240
|
};
|
|
1241
|
+
export {};
|
|
1235
1242
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAKA,KAAK,YAAY,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAElD,UAAU,iBAAiB;IACzB,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC1D,IAAI,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;C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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAhDN,CAAA;iBAC9C,CAAJ;;;;;;;;;;;;;;;;qBAbe,CAAC;;;;;;;;;;;;;;;;CAmIf,CAAC"}
|
package/dist/auth.js
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
import { createAuthClient } from "better-auth/client";
|
|
2
2
|
import { anonymousClient } from "better-auth/client/plugins";
|
|
3
3
|
import { computed } from "nanostores";
|
|
4
|
+
// Only create once on the global object
|
|
5
|
+
export const SessionEvents = (() => {
|
|
6
|
+
if (window.__SessionEvents)
|
|
7
|
+
return window.__SessionEvents;
|
|
8
|
+
const listeners = {
|
|
9
|
+
login: [],
|
|
10
|
+
logout: [],
|
|
11
|
+
change: [],
|
|
12
|
+
};
|
|
13
|
+
const events = {
|
|
14
|
+
on(event, callback) {
|
|
15
|
+
listeners[event].push(callback);
|
|
16
|
+
return () => {
|
|
17
|
+
const i = listeners[event].indexOf(callback);
|
|
18
|
+
if (i >= 0)
|
|
19
|
+
listeners[event].splice(i, 1);
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
emit(event) {
|
|
23
|
+
listeners[event].forEach((cb) => cb());
|
|
24
|
+
listeners.change.forEach((cb) => cb());
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
window.__SessionEvents = events;
|
|
28
|
+
return events;
|
|
29
|
+
})();
|
|
4
30
|
export const AuraAuth = (url, workspace) => {
|
|
5
31
|
const _onUserLoadedCallbacks = [];
|
|
6
32
|
const _onUserNotFoundCallbacks = [];
|
|
@@ -8,9 +34,7 @@ export const AuraAuth = (url, workspace) => {
|
|
|
8
34
|
let User = null;
|
|
9
35
|
const authClient = createAuthClient({
|
|
10
36
|
baseURL: url + "/api/auth/" + workspace,
|
|
11
|
-
plugins: [
|
|
12
|
-
anonymousClient()
|
|
13
|
-
],
|
|
37
|
+
plugins: [anonymousClient()],
|
|
14
38
|
fetchOptions: {
|
|
15
39
|
credentials: "include",
|
|
16
40
|
},
|
|
@@ -18,15 +42,15 @@ export const AuraAuth = (url, workspace) => {
|
|
|
18
42
|
const Session = computed(authClient.useSession, (session) => {
|
|
19
43
|
if (!session?.data?.user)
|
|
20
44
|
return session;
|
|
45
|
+
const Events = window.__SessionEvents;
|
|
46
|
+
Events.emit("change");
|
|
21
47
|
return {
|
|
22
48
|
...session,
|
|
23
49
|
data: {
|
|
24
50
|
...session.data,
|
|
25
51
|
user: {
|
|
26
52
|
...session.data.user,
|
|
27
|
-
image: session.data.user.image
|
|
28
|
-
? url + session.data.user.image
|
|
29
|
-
: null,
|
|
53
|
+
image: session.data.user.image ? url + session.data.user.image : null,
|
|
30
54
|
},
|
|
31
55
|
},
|
|
32
56
|
};
|
|
@@ -80,7 +104,9 @@ export const AuraAuth = (url, workspace) => {
|
|
|
80
104
|
},
|
|
81
105
|
OnUserLoaded,
|
|
82
106
|
OnUserNotFound,
|
|
83
|
-
get User() {
|
|
107
|
+
get User() {
|
|
108
|
+
return User;
|
|
109
|
+
},
|
|
84
110
|
Oauth: (() => {
|
|
85
111
|
const withDefaultCallback = (provider, data) => authClient.signIn.social({
|
|
86
112
|
provider,
|
|
@@ -113,6 +139,6 @@ export const AuraAuth = (url, workspace) => {
|
|
|
113
139
|
Anonymous: {
|
|
114
140
|
SignUp: authClient.signIn.anonymous,
|
|
115
141
|
Delete: authClient.deleteAnonymousUser,
|
|
116
|
-
}
|
|
142
|
+
},
|
|
117
143
|
};
|
|
118
144
|
};
|