fivebit-client 0.2.0 → 0.2.1

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.
@@ -17,6 +17,14 @@ export declare class AuthClient {
17
17
  } | {
18
18
  error: string;
19
19
  }>;
20
+ signInWithOAuth(provider: 'google' | 'github', credential: {
21
+ idToken?: string;
22
+ code?: string;
23
+ }): Promise<{
24
+ session: AuthSession;
25
+ } | {
26
+ error: string;
27
+ }>;
20
28
  signOut(): Promise<void>;
21
29
  get token(): string | null;
22
30
  }
@@ -23,6 +23,16 @@ class AuthClient {
23
23
  this._token = data.session.token;
24
24
  return data;
25
25
  }
26
+ async signInWithOAuth(provider, credential) {
27
+ const r = await fetch(`${this.baseUrl}/api/auth/oauth`, {
28
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
29
+ body: JSON.stringify({ provider, ...credential }),
30
+ });
31
+ const data = await r.json();
32
+ if ('session' in data)
33
+ this._token = data.session.token;
34
+ return data;
35
+ }
26
36
  async signOut() {
27
37
  if (this._token) {
28
38
  await fetch(`${this.baseUrl}/api/auth/logout`, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fivebit-client",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "5bit client SDK — deterministic, content-addressed database",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/AuthClient.ts CHANGED
@@ -24,6 +24,16 @@ export class AuthClient {
24
24
  return data;
25
25
  }
26
26
 
27
+ async signInWithOAuth(provider: 'google' | 'github', credential: { idToken?: string; code?: string }): Promise<{ session: AuthSession } | { error: string }> {
28
+ const r = await fetch(`${this.baseUrl}/api/auth/oauth`, {
29
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
30
+ body: JSON.stringify({ provider, ...credential }),
31
+ });
32
+ const data = await r.json();
33
+ if ('session' in data) this._token = data.session.token;
34
+ return data;
35
+ }
36
+
27
37
  async signOut(): Promise<void> {
28
38
  if (this._token) {
29
39
  await fetch(`${this.baseUrl}/api/auth/logout`, {