prostgles-client 4.0.199 → 4.0.201
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 +60 -13
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js +22 -18
- package/dist/index.js +1 -1
- package/dist/index.no-sync.js +1 -1
- package/package.json +2 -2
package/dist/Auth.d.ts
CHANGED
|
@@ -11,24 +11,16 @@ type ClientAuthSuccess<T> = T & {
|
|
|
11
11
|
*/
|
|
12
12
|
redirect_url?: string;
|
|
13
13
|
};
|
|
14
|
-
export type
|
|
15
|
-
export type PasswordLoginResponse = ClientAuthSuccess<AuthResponse.PasswordLoginFailure | AuthResponse.PasswordLoginSuccess>;
|
|
14
|
+
export type PasswordLoginResponse = ClientAuthSuccess<AuthResponse.PasswordLoginFailure | AuthResponse.PasswordLoginSuccess | AuthResponse.MagicLinkAuthSuccess | AuthResponse.MagicLinkAuthFailure | AuthResponse.OAuthRegisterSuccess | AuthResponse.OAuthRegisterFailure>;
|
|
16
15
|
export type PasswordRegisterResponse = ClientAuthSuccess<AuthResponse.PasswordLoginFailure | AuthResponse.PasswordLoginSuccess>;
|
|
17
16
|
export type PasswordRegister = (params: AuthRequest.RegisterData) => Promise<PasswordRegisterResponse>;
|
|
18
17
|
export type PasswordLogin = (params: AuthRequest.LoginData) => Promise<PasswordLoginResponse>;
|
|
19
|
-
export type MagicLinkAuth = (params: AuthRequest.RegisterData) => Promise<MagicLinkAuthResponse>;
|
|
20
|
-
export type EmailAuth<Type extends "register" | "login"> = {
|
|
21
|
-
withPassword?: Type extends "register" ? PasswordRegister : PasswordLogin;
|
|
22
|
-
withMagicLink?: undefined;
|
|
23
|
-
} | {
|
|
24
|
-
withPassword?: undefined;
|
|
25
|
-
withMagicLink?: MagicLinkAuth;
|
|
26
|
-
};
|
|
27
18
|
type LoginSignupOptions = {
|
|
28
19
|
prefferedLogin: "email" | IdentityProvider | undefined;
|
|
29
20
|
loginWithProvider: undefined | WithProviderLogin;
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
loginType: AuthSocketSchema["loginType"];
|
|
22
|
+
login: undefined | PasswordLogin;
|
|
23
|
+
signupWithEmailAndPassword: undefined | PasswordRegister;
|
|
32
24
|
providers: AuthSocketSchema["providers"];
|
|
33
25
|
};
|
|
34
26
|
type AuthStateLoggedOut = LoginSignupOptions & {
|
|
@@ -42,6 +34,61 @@ type AuthStateLoggedIn = LoginSignupOptions & {
|
|
|
42
34
|
};
|
|
43
35
|
export type AuthHandler = AuthStateLoggedOut | AuthStateLoggedIn;
|
|
44
36
|
export declare const setupAuth: ({ authData: authConfig, socket, onReload }: Args) => AuthHandler;
|
|
45
|
-
export declare const
|
|
37
|
+
export declare const authRequest: <T extends (import("prostgles-types").CommonAuthFailure & {
|
|
38
|
+
/**
|
|
39
|
+
* This is a client-only property that is obtained from server redirect response
|
|
40
|
+
*/
|
|
41
|
+
redirect_url?: string | undefined;
|
|
42
|
+
}) | ({
|
|
43
|
+
success: false;
|
|
44
|
+
code: "no-match";
|
|
45
|
+
message?: string | undefined;
|
|
46
|
+
} & {
|
|
47
|
+
/**
|
|
48
|
+
* This is a client-only property that is obtained from server redirect response
|
|
49
|
+
*/
|
|
50
|
+
redirect_url?: string | undefined;
|
|
51
|
+
}) | ({
|
|
52
|
+
success: false;
|
|
53
|
+
code: "inactive-account";
|
|
54
|
+
message?: string | undefined;
|
|
55
|
+
} & {
|
|
56
|
+
/**
|
|
57
|
+
* This is a client-only property that is obtained from server redirect response
|
|
58
|
+
*/
|
|
59
|
+
redirect_url?: string | undefined;
|
|
60
|
+
}) | ({
|
|
61
|
+
success: false;
|
|
62
|
+
code: "totp-token-missing" | "invalid-username" | "username-missing" | "password-missing" | "invalid-password" | "is-from-OAuth" | "is-from-magic-link" | "invalid-totp-recovery-code" | "invalid-totp-code" | "email-not-confirmed";
|
|
63
|
+
message?: string | undefined;
|
|
64
|
+
} & {
|
|
65
|
+
/**
|
|
66
|
+
* This is a client-only property that is obtained from server redirect response
|
|
67
|
+
*/
|
|
68
|
+
redirect_url?: string | undefined;
|
|
69
|
+
}) | (AuthResponse.AuthSuccess & {
|
|
70
|
+
/**
|
|
71
|
+
* This is a client-only property that is obtained from server redirect response
|
|
72
|
+
*/
|
|
73
|
+
redirect_url?: string | undefined;
|
|
74
|
+
}) | ({
|
|
75
|
+
success: false;
|
|
76
|
+
code: "expired-magic-link" | "invalid-magic-link" | "used-magic-link";
|
|
77
|
+
message?: string | undefined;
|
|
78
|
+
} & {
|
|
79
|
+
/**
|
|
80
|
+
* This is a client-only property that is obtained from server redirect response
|
|
81
|
+
*/
|
|
82
|
+
redirect_url?: string | undefined;
|
|
83
|
+
}) | ({
|
|
84
|
+
success: false;
|
|
85
|
+
code: "provider-issue";
|
|
86
|
+
message?: string | undefined;
|
|
87
|
+
} & {
|
|
88
|
+
/**
|
|
89
|
+
* This is a client-only property that is obtained from server redirect response
|
|
90
|
+
*/
|
|
91
|
+
redirect_url?: string | undefined;
|
|
92
|
+
})>(path: string, data: object, method?: "GET") => Promise<T>;
|
|
46
93
|
export {};
|
|
47
94
|
//# sourceMappingURL=Auth.d.ts.map
|
package/dist/Auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Auth.d.ts","sourceRoot":"","sources":["../lib/Auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EAGT,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAIzB,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,GAAG,CAAC;IACZ,QAAQ,EAAE,gBAAgB,GAAG,SAAS,CAAC;IACvC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;CACpC,CAAC;AAEF,KAAK,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC,CAAC;AAEzE,KAAK,iBAAiB,CA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IACxB,cAAc,EAAE,OAAO,GAAG,gBAAgB,GAAG,SAAS,CAAC;IACvD,iBAAiB,EAAE,SAAS,GAAG,iBAAiB,CAAC;IACjD,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACzC,KAAK,EAAE,SAAS,GAAG,aAAa,CAAC;IACjC,0BAA0B,EAAE,SAAS,GAAG,gBAAgB,CAAC;IACzD,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;CAC1C,CAAC;AAEF,KAAK,kBAAkB,GAAG,kBAAkB,GAAG;IAC7C,UAAU,EAAE,KAAK,CAAC;IAClB,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,KAAK,iBAAiB,GAAG,kBAAkB,GAAG;IAC5C,UAAU,EAAE,IAAI,CAAC;IACjB,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,kBAAkB,GAAG,iBAAiB,CAAC;AAEjE,eAAO,MAAM,SAAS,+CAAgD,IAAI,KAAG,WAmF5E,CAAC;AAEF,eAAO,MAAM,WAAW;IAjItB;;OAEG;;;;;;;IAFH;;OAEG;;;;;;;IAFH;;OAEG;;;;;;;IAFH;;OAEG;;;IAFH;;OAEG;;;;;;;IAFH;;OAEG;;;;;;;IAFH;;OAEG;;UAgIG,MAAM,QACN,MAAM,WACH,KAAK,eAgCf,CAAC"}
|
package/dist/Auth.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.authRequest = exports.setupAuth = void 0;
|
|
4
4
|
const prostgles_types_1 = require("prostgles-types");
|
|
5
5
|
const prostgles_1 = require("./prostgles");
|
|
6
6
|
const setupAuth = ({ authData: authConfig, socket, onReload }) => {
|
|
@@ -10,11 +10,14 @@ const setupAuth = ({ authData: authConfig, socket, onReload }) => {
|
|
|
10
10
|
if (onReload)
|
|
11
11
|
onReload();
|
|
12
12
|
else if (prostgles_1.hasWnd) {
|
|
13
|
-
|
|
13
|
+
console.log("prostgles page reload due to authguard", res);
|
|
14
|
+
setTimeout(() => {
|
|
15
|
+
window.location.reload();
|
|
16
|
+
}, 200);
|
|
14
17
|
}
|
|
15
18
|
}
|
|
16
19
|
};
|
|
17
|
-
socket.emit(prostgles_types_1.CHANNELS.AUTHGUARD, JSON.stringify(window.location), (
|
|
20
|
+
socket.emit(prostgles_types_1.CHANNELS.AUTHGUARD, JSON.stringify(window.location), (_err, res) => {
|
|
18
21
|
doReload(res);
|
|
19
22
|
});
|
|
20
23
|
socket.removeAllListeners(prostgles_types_1.CHANNELS.AUTHGUARD);
|
|
@@ -23,14 +26,15 @@ const setupAuth = ({ authData: authConfig, socket, onReload }) => {
|
|
|
23
26
|
});
|
|
24
27
|
}
|
|
25
28
|
const loginSignupOptions = {
|
|
29
|
+
loginType: authConfig === null || authConfig === void 0 ? void 0 : authConfig.loginType,
|
|
26
30
|
login: undefined,
|
|
27
31
|
prefferedLogin: undefined,
|
|
28
32
|
loginWithProvider: undefined,
|
|
29
|
-
|
|
33
|
+
signupWithEmailAndPassword: undefined,
|
|
30
34
|
providers: authConfig === null || authConfig === void 0 ? void 0 : authConfig.providers,
|
|
31
35
|
};
|
|
32
36
|
if (authConfig) {
|
|
33
|
-
const { providers,
|
|
37
|
+
const { providers, signupWithEmailAndPassword, loginType } = authConfig;
|
|
34
38
|
loginSignupOptions.loginWithProvider =
|
|
35
39
|
(0, prostgles_types_1.isEmpty)(providers) ? undefined : (providers &&
|
|
36
40
|
Object.entries(providers).reduce((acc, [provider, { url }]) => {
|
|
@@ -43,16 +47,16 @@ const setupAuth = ({ authData: authConfig, socket, onReload }) => {
|
|
|
43
47
|
const { search } = window.location;
|
|
44
48
|
return url + search;
|
|
45
49
|
};
|
|
46
|
-
loginSignupOptions.login =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
loginSignupOptions.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
loginSignupOptions.login =
|
|
51
|
+
loginType &&
|
|
52
|
+
(async (params) => {
|
|
53
|
+
return (0, exports.authRequest)(addSearchInCaseItHasReturnUrl("/login"), params);
|
|
54
|
+
});
|
|
55
|
+
loginSignupOptions.signupWithEmailAndPassword =
|
|
56
|
+
signupWithEmailAndPassword &&
|
|
57
|
+
((params) => {
|
|
58
|
+
return (0, exports.authRequest)(addSearchInCaseItHasReturnUrl(signupWithEmailAndPassword.url), params);
|
|
59
|
+
});
|
|
56
60
|
}
|
|
57
61
|
if (!(authConfig === null || authConfig === void 0 ? void 0 : authConfig.user)) {
|
|
58
62
|
return {
|
|
@@ -71,9 +75,9 @@ const setupAuth = ({ authData: authConfig, socket, onReload }) => {
|
|
|
71
75
|
};
|
|
72
76
|
};
|
|
73
77
|
exports.setupAuth = setupAuth;
|
|
74
|
-
const
|
|
78
|
+
const authRequest = async (path, data, method) => {
|
|
75
79
|
const rawResponse = await fetch(path, {
|
|
76
|
-
method: "POST",
|
|
80
|
+
method: method !== null && method !== void 0 ? method : "POST",
|
|
77
81
|
headers: {
|
|
78
82
|
Accept: "application/json",
|
|
79
83
|
"Content-Type": "application/json",
|
|
@@ -99,4 +103,4 @@ const postAuthData = async (path, data) => {
|
|
|
99
103
|
}
|
|
100
104
|
return responseObject;
|
|
101
105
|
};
|
|
102
|
-
exports.
|
|
106
|
+
exports.authRequest = authRequest;
|