prostgles-client 4.0.145 → 4.0.146

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/lib/Auth.ts CHANGED
@@ -19,17 +19,20 @@ type EmailAuth =
19
19
  withMagicLink?: (params: { username: string; }) => Promise<any>;
20
20
  }
21
21
 
22
- type AuthStateLoggedOut = {
23
- isLoggedin: false;
24
- user?: undefined;
22
+ type LoginSignupOptions = {
25
23
  prefferedLogin: string;
26
- login?: {
24
+ login: undefined | {
27
25
  withProvider?: WithProviderLogin;
28
26
  } & EmailAuth;
29
- register?: EmailAuth
27
+ register: undefined | EmailAuth;
28
+ }
29
+
30
+ type AuthStateLoggedOut = LoginSignupOptions & {
31
+ isLoggedin: false;
32
+ user?: undefined;
30
33
  };
31
34
 
32
- type AuthStateLoggedIn = {
35
+ type AuthStateLoggedIn = LoginSignupOptions & {
33
36
  isLoggedin: true;
34
37
  user: AnyObject;
35
38
  prefferedLogin: string;
@@ -60,8 +63,14 @@ export const setupAuth = ({ authData: authConfig, socket, onReload }: Args): Aut
60
63
  });
61
64
  }
62
65
 
63
- if(!authConfig?.user){
64
- const { providers, register, loginType } = authConfig ?? {};
66
+ const loginSignupOptions: LoginSignupOptions = {
67
+ login: undefined,
68
+ prefferedLogin: "",
69
+ register: undefined,
70
+ }
71
+
72
+ if(authConfig){
73
+ const { providers, register, loginType } = authConfig;
65
74
  const withProvider: WithProviderLogin | undefined = isEmpty(providers)? undefined : providers && Object.entries(providers).reduce((acc, [provider, { url }]) => {
66
75
  acc[provider as IdentityProvider] = () => {
67
76
  window.location.assign(url);
@@ -69,23 +78,27 @@ export const setupAuth = ({ authData: authConfig, socket, onReload }: Args): Aut
69
78
  return acc;
70
79
  }, {});
71
80
 
81
+ loginSignupOptions.login = {
82
+ withProvider,
83
+ ...(loginType && {
84
+ [loginType]: async (params) => {
85
+ return POST("/login", params);
86
+ },
87
+ }),
88
+ };
89
+
90
+ loginSignupOptions.register = register?.type? {
91
+ [register.type]: (params) => {
92
+ POST(register.url, params);
93
+ }
94
+ } : undefined;
95
+ }
96
+
97
+ if(!authConfig?.user){
72
98
  return {
73
99
  isLoggedin: false,
74
100
  user: undefined,
75
- prefferedLogin: "",
76
- login: {
77
- withProvider,
78
- ...(loginType && {
79
- [loginType]: async (params) => {
80
- return POST("/login", params);
81
- },
82
- }),
83
- },
84
- register: register?.type? {
85
- [register.type]: (params) => {
86
- POST(register.url, params);
87
- }
88
- } : undefined
101
+ ...loginSignupOptions
89
102
  } satisfies AuthStateLoggedOut;
90
103
  }
91
104
 
@@ -93,9 +106,9 @@ export const setupAuth = ({ authData: authConfig, socket, onReload }: Args): Aut
93
106
  isLoggedin: true,
94
107
  user: authConfig.user,
95
108
  logout: () => {
96
-
109
+ window.location.assign("/logout");
97
110
  },
98
- prefferedLogin: "",
111
+ ...loginSignupOptions
99
112
  } satisfies AuthStateLoggedIn;
100
113
  }
101
114
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prostgles-client",
3
- "version": "4.0.145",
3
+ "version": "4.0.146",
4
4
  "description": "Reactive client for Postgres",
5
5
  "main": "dist/prostgles-full.js",
6
6
  "types": "dist/prostgles-full.d.ts",
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "..": {
19
19
  "name": "prostgles-client",
20
- "version": "4.0.144",
20
+ "version": "4.0.145",
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
23
  "i": "^0.3.7",