@inflector/aura 0.1.8 → 0.1.9
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 +3 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +48 -1
- package/package.json +1 -1
package/dist/auth.d.ts
CHANGED
|
@@ -79,6 +79,9 @@ export declare const AuraAuth: (url: string, workspace: string) => {
|
|
|
79
79
|
message?: string | undefined;
|
|
80
80
|
}, FetchOptions["throw"] extends true ? true : false>>;
|
|
81
81
|
};
|
|
82
|
+
OnUserLoaded: (fn: () => void | Promise<void>) => void;
|
|
83
|
+
OnUserNotFound: (fn: () => void | Promise<void>) => void;
|
|
84
|
+
readonly User: any;
|
|
82
85
|
Oauth: {
|
|
83
86
|
Google: (data?: Omit<import("better-auth").Prettify<{
|
|
84
87
|
provider: (string & {}) | "github" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "huggingface" | "slack" | "spotify" | "twitch" | "twitter" | "dropbox" | "kick" | "linear" | "linkedin" | "gitlab" | "tiktok" | "reddit" | "roblox" | "salesforce" | "vk" | "zoom" | "notion" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "vercel";
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -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
|
|
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,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAhBzC,CAAC;iBACN,CAAH;;;;;;;;;;;;;;;;qBAdG,CAAC;;;;;;;;;;;;;;;;CAuFZ,CAAA"}
|
package/dist/auth.js
CHANGED
|
@@ -2,6 +2,10 @@ import { createAuthClient } from "better-auth/client";
|
|
|
2
2
|
import { anonymousClient } from "better-auth/client/plugins";
|
|
3
3
|
import { computed } from "nanostores";
|
|
4
4
|
export const AuraAuth = (url, workspace) => {
|
|
5
|
+
const _onUserLoadedCallbacks = [];
|
|
6
|
+
const _onUserNotFoundCallbacks = [];
|
|
7
|
+
let _initialized = false;
|
|
8
|
+
let User = null;
|
|
5
9
|
const authClient = createAuthClient({
|
|
6
10
|
baseURL: url + "/api/auth/" + workspace,
|
|
7
11
|
plugins: [
|
|
@@ -27,13 +31,56 @@ export const AuraAuth = (url, workspace) => {
|
|
|
27
31
|
},
|
|
28
32
|
};
|
|
29
33
|
});
|
|
30
|
-
|
|
34
|
+
const triggerCallbacks = async (callbacks) => {
|
|
35
|
+
for (const fn of callbacks)
|
|
36
|
+
await fn();
|
|
37
|
+
};
|
|
38
|
+
const initialize = async () => {
|
|
39
|
+
try {
|
|
40
|
+
const data = await authClient.getSession();
|
|
41
|
+
if (data.data?.user) {
|
|
42
|
+
User = data.data.user;
|
|
43
|
+
await triggerCallbacks(_onUserLoadedCallbacks);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
await triggerCallbacks(_onUserNotFoundCallbacks);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
console.error("Error initializing auth:", err);
|
|
51
|
+
await triggerCallbacks(_onUserNotFoundCallbacks);
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
_initialized = true;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const OnUserLoaded = (fn) => {
|
|
58
|
+
if (_initialized && User) {
|
|
59
|
+
Promise.resolve(fn());
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
_onUserLoadedCallbacks.push(fn);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const OnUserNotFound = (fn) => {
|
|
66
|
+
if (_initialized && !User) {
|
|
67
|
+
Promise.resolve(fn());
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
_onUserNotFoundCallbacks.push(fn);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
// Initialize auth on creation
|
|
74
|
+
initialize();
|
|
31
75
|
return {
|
|
32
76
|
Logout: authClient.signOut,
|
|
33
77
|
Email: {
|
|
34
78
|
SignUp: authClient.signUp.email,
|
|
35
79
|
Login: authClient.signIn.email,
|
|
36
80
|
},
|
|
81
|
+
OnUserLoaded,
|
|
82
|
+
OnUserNotFound,
|
|
83
|
+
get User() { return User; },
|
|
37
84
|
Oauth: (() => {
|
|
38
85
|
const withDefaultCallback = (provider, data) => authClient.signIn.social({
|
|
39
86
|
provider,
|