@protobase/client 0.1.0 → 0.1.2
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 -1
- package/dist/auth.js +21 -2
- package/package.json +3 -3
package/dist/auth.d.ts
CHANGED
|
@@ -24,10 +24,11 @@ export type AuthSessionOptions = {
|
|
|
24
24
|
};
|
|
25
25
|
/** The expiry of a JWT in milliseconds, read from its payload (the signature is the server's business). */
|
|
26
26
|
export declare const tokenExpiry: (token: string) => number;
|
|
27
|
-
/** `needsAdmin` while no user exists yet; `passwordReset` when the server can email reset links
|
|
27
|
+
/** `needsAdmin` while no user exists yet; `passwordReset` when the server can email reset links; `socialProviders` the ids of the sign-in providers, for example `github`. */
|
|
28
28
|
export type SetupStatus = {
|
|
29
29
|
needsAdmin: boolean;
|
|
30
30
|
passwordReset: boolean;
|
|
31
|
+
socialProviders: string[];
|
|
31
32
|
};
|
|
32
33
|
/**
|
|
33
34
|
* The browser side of Better Auth: sign in with email and password, and a short-lived JWT held in memory only
|
|
@@ -42,6 +43,11 @@ export declare const createAuthSession: (options?: AuthSessionOptions) => {
|
|
|
42
43
|
/** The signed-in user from the session cookie, or `undefined`. */
|
|
43
44
|
session: () => Promise<AuthUser | undefined>;
|
|
44
45
|
signIn: (email: string, password: string) => Promise<AuthUser>;
|
|
46
|
+
/**
|
|
47
|
+
* Starts sign-in with a provider such as `github`: resolves with the provider's authorization URL, for the page to go to.
|
|
48
|
+
* The provider sends the browser back to `callbackURL` signed in, or with `?error=<code>`.
|
|
49
|
+
*/
|
|
50
|
+
signInSocial: (provider: string, callbackURL: string) => Promise<string>;
|
|
45
51
|
signOut: () => Promise<void>;
|
|
46
52
|
/**
|
|
47
53
|
* Emails a reset link when an account has this address; the answer is the same either way. The link leads back to
|
package/dist/auth.js
CHANGED
|
@@ -74,7 +74,8 @@ const createAuthSession = (options = {}) => {
|
|
|
74
74
|
const body = await response.json();
|
|
75
75
|
return {
|
|
76
76
|
needsAdmin: Boolean(body.needsAdmin),
|
|
77
|
-
passwordReset: Boolean(body.passwordReset)
|
|
77
|
+
passwordReset: Boolean(body.passwordReset),
|
|
78
|
+
socialProviders: body.socialProviders ?? []
|
|
78
79
|
};
|
|
79
80
|
},
|
|
80
81
|
/** The signed-in user from the session cookie, or `undefined`. */
|
|
@@ -91,6 +92,20 @@ const createAuthSession = (options = {}) => {
|
|
|
91
92
|
await token({ refresh: true });
|
|
92
93
|
return data.user;
|
|
93
94
|
},
|
|
95
|
+
/**
|
|
96
|
+
* Starts sign-in with a provider such as `github`: resolves with the provider's authorization URL, for the page to go to.
|
|
97
|
+
* The provider sends the browser back to `callbackURL` signed in, or with `?error=<code>`.
|
|
98
|
+
*/
|
|
99
|
+
signInSocial: async (provider, callbackURL) => {
|
|
100
|
+
const { data, error } = await client.signIn.social({
|
|
101
|
+
provider,
|
|
102
|
+
callbackURL,
|
|
103
|
+
errorCallbackURL: callbackURL,
|
|
104
|
+
disableRedirect: true
|
|
105
|
+
});
|
|
106
|
+
if (error || !data?.url) throw new AuthError(error?.message || "Sign-in failed", error?.status ?? 500, error?.code);
|
|
107
|
+
return data.url;
|
|
108
|
+
},
|
|
94
109
|
signOut: async () => {
|
|
95
110
|
forget();
|
|
96
111
|
await client.signOut();
|
|
@@ -129,10 +144,14 @@ const createStaticSession = (token, user = {
|
|
|
129
144
|
token: async () => token,
|
|
130
145
|
status: async () => ({
|
|
131
146
|
needsAdmin: false,
|
|
132
|
-
passwordReset: false
|
|
147
|
+
passwordReset: false,
|
|
148
|
+
socialProviders: []
|
|
133
149
|
}),
|
|
134
150
|
session: async () => user,
|
|
135
151
|
signIn: async () => user,
|
|
152
|
+
signInSocial: async () => {
|
|
153
|
+
throw new AuthError("A static session cannot sign in with a provider", 400);
|
|
154
|
+
},
|
|
136
155
|
signOut: async () => void 0,
|
|
137
156
|
requestPasswordReset: async () => void 0,
|
|
138
157
|
resetPassword: async () => void 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Typed fetch client for the Protobase REST API.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"better-auth": "^1.7.7",
|
|
29
|
-
"@protobase/layout": "0.1.
|
|
30
|
-
"@protobase/schema": "0.1.
|
|
29
|
+
"@protobase/layout": "0.1.2",
|
|
30
|
+
"@protobase/schema": "0.1.2"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsdown"
|