@inflector/aura 0.1.9 → 0.1.11

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 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
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,EAAE,WAAW,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAuDzB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;yBAQxB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BArDrC,CAAC;iBAChB,CAAH;;;;;;;;;;;;;;;;qBAZe,CAAC;;;;;;;;;;;;;;;;CAuIhB,CAAC"}
package/dist/auth.js CHANGED
@@ -1,6 +1,35 @@
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
+ window.dispatchEvent(new CustomEvent("__AuraSession", {
26
+ detail: { type: event },
27
+ }));
28
+ },
29
+ };
30
+ window.__SessionEvents = events;
31
+ return events;
32
+ })();
4
33
  export const AuraAuth = (url, workspace) => {
5
34
  const _onUserLoadedCallbacks = [];
6
35
  const _onUserNotFoundCallbacks = [];
@@ -8,9 +37,7 @@ export const AuraAuth = (url, workspace) => {
8
37
  let User = null;
9
38
  const authClient = createAuthClient({
10
39
  baseURL: url + "/api/auth/" + workspace,
11
- plugins: [
12
- anonymousClient()
13
- ],
40
+ plugins: [anonymousClient()],
14
41
  fetchOptions: {
15
42
  credentials: "include",
16
43
  },
@@ -18,15 +45,15 @@ export const AuraAuth = (url, workspace) => {
18
45
  const Session = computed(authClient.useSession, (session) => {
19
46
  if (!session?.data?.user)
20
47
  return session;
48
+ const Events = window.__SessionEvents;
49
+ Events.emit("change");
21
50
  return {
22
51
  ...session,
23
52
  data: {
24
53
  ...session.data,
25
54
  user: {
26
55
  ...session.data.user,
27
- image: session.data.user.image
28
- ? url + session.data.user.image
29
- : null,
56
+ image: session.data.user.image ? url + session.data.user.image : null,
30
57
  },
31
58
  },
32
59
  };
@@ -80,7 +107,9 @@ export const AuraAuth = (url, workspace) => {
80
107
  },
81
108
  OnUserLoaded,
82
109
  OnUserNotFound,
83
- get User() { return User; },
110
+ get User() {
111
+ return User;
112
+ },
84
113
  Oauth: (() => {
85
114
  const withDefaultCallback = (provider, data) => authClient.signIn.social({
86
115
  provider,
@@ -113,6 +142,6 @@ export const AuraAuth = (url, workspace) => {
113
142
  Anonymous: {
114
143
  SignUp: authClient.signIn.anonymous,
115
144
  Delete: authClient.deleteAnonymousUser,
116
- }
145
+ },
117
146
  };
118
147
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inflector/aura",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",