pocketbase-react 0.1.20 → 0.1.21

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.
Files changed (41) hide show
  1. package/dist/pocketbase-react.js +194 -290
  2. package/dist/pocketbase-react.min.js +3 -3
  3. package/es/context/Pocketbase.js +18 -3
  4. package/es/context/auth.js +0 -17
  5. package/es/hooks/useAppContent.js +3 -4
  6. package/es/store/actions/index.d.ts +1 -2
  7. package/es/store/actions/index.js +1 -2
  8. package/es/store/reducers/index.d.ts +3 -8
  9. package/es/store/reducers/index.js +2 -4
  10. package/es/store/reducers/subscriptions.d.ts +1 -4
  11. package/es/store/reducers/subscriptions.js +5 -14
  12. package/es/store/store.d.ts +3 -4
  13. package/es/store/types/index.d.ts +0 -7
  14. package/es/store/types/index.js +1 -7
  15. package/lib/context/Pocketbase.js +17 -2
  16. package/lib/context/auth.js +0 -17
  17. package/lib/hooks/useAppContent.js +3 -6
  18. package/lib/store/actions/index.js +1 -3
  19. package/lib/store/reducers/index.js +1 -3
  20. package/lib/store/reducers/subscriptions.js +5 -14
  21. package/lib/store/types/index.js +2 -14
  22. package/package.json +1 -1
  23. package/src/context/Pocketbase.tsx +16 -5
  24. package/src/context/auth.tsx +1 -23
  25. package/src/hooks/useAppContent.ts +3 -3
  26. package/src/store/actions/index.tsx +1 -2
  27. package/src/store/reducers/index.tsx +3 -9
  28. package/src/store/reducers/subscriptions.tsx +6 -23
  29. package/src/store/types/index.ts +0 -15
  30. package/es/service/Authentication.d.ts +0 -23
  31. package/es/service/Authentication.js +0 -32
  32. package/es/store/actions/auth.d.ts +0 -9
  33. package/es/store/actions/auth.js +0 -26
  34. package/es/store/reducers/auth.d.ts +0 -12
  35. package/es/store/reducers/auth.js +0 -36
  36. package/lib/service/Authentication.js +0 -37
  37. package/lib/store/actions/auth.js +0 -37
  38. package/lib/store/reducers/auth.js +0 -44
  39. package/src/service/Authentication.ts +0 -40
  40. package/src/store/actions/auth.tsx +0 -41
  41. package/src/store/reducers/auth.tsx +0 -57
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.subscriptionsAction = exports.recordsAction = exports.authAction = void 0;
4
+ exports.subscriptionsAction = exports.recordsAction = void 0;
5
5
  var recordsAction = _interopRequireWildcard(require("./records"));
6
6
  exports.recordsAction = recordsAction;
7
7
  var subscriptionsAction = _interopRequireWildcard(require("./subscriptions"));
8
8
  exports.subscriptionsAction = subscriptionsAction;
9
- var authAction = _interopRequireWildcard(require("./auth"));
10
- exports.authAction = authAction;
11
9
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
10
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -5,10 +5,8 @@ exports.appReducer = void 0;
5
5
  var _redux = require("redux");
6
6
  var _records = require("./records");
7
7
  var _subscriptions = require("./subscriptions");
8
- var _auth = require("./auth");
9
8
  const appReducer = (0, _redux.combineReducers)({
10
9
  records: _records.records,
11
- subscriptions: _subscriptions.subscriptions,
12
- auth: _auth.auth
10
+ subscriptions: _subscriptions.subscriptions
13
11
  });
14
12
  exports.appReducer = appReducer;
@@ -6,30 +6,21 @@ var ReduxType = _interopRequireWildcard(require("../types"));
6
6
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
7
7
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
8
8
  function appendSubscription(subscription, subscriptions) {
9
- return [...subscriptions, subscription];
9
+ return subscriptions.includes(subscription) ? subscriptions : [...subscriptions, subscription];
10
10
  }
11
11
  function deleteSubscription(subscription, subscriptions) {
12
12
  return subscriptions.filter(sub => sub !== subscription);
13
13
  }
14
- const subscriptions = (state = {
15
- subscriptions: []
16
- }, action) => {
17
- const list = state.subscriptions;
14
+ const subscriptions = (state = [], action) => {
18
15
  switch (action.type) {
19
16
  case ReduxType.SET_SUBSCRIPTIONS:
20
17
  if (Array.isArray(action.payload)) {
21
- return {
22
- subscriptions: action.payload
23
- };
18
+ return action.payload;
24
19
  }
25
20
  case ReduxType.ADD_SUBSCRIPTION:
26
- return {
27
- subscriptions: appendSubscription(action.payload, list)
28
- };
21
+ return appendSubscription(action.payload, state);
29
22
  case ReduxType.DELETE_SUBSCRIPTION:
30
- return {
31
- subscriptions: deleteSubscription(action.payload, list)
32
- };
23
+ return deleteSubscription(action.payload, state);
33
24
  default:
34
25
  return state;
35
26
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.UPDATE_RECORD = exports.SET_TOKEN = exports.SET_SUBSCRIPTIONS = exports.SET_RECORDS = exports.SET_MODEL = exports.SET_COOKIE = exports.DELETE_TOKEN = exports.DELETE_SUBSCRIPTION = exports.DELETE_RECORDS = exports.DELETE_RECORD = exports.DELETE_MODEL = exports.DELETE_COOKIE = exports.ADD_SUBSCRIPTION = exports.ADD_RECORDS = exports.ADD_RECORD = void 0;
4
+ exports.UPDATE_RECORD = exports.SET_SUBSCRIPTIONS = exports.SET_RECORDS = exports.DELETE_SUBSCRIPTION = exports.DELETE_RECORDS = exports.DELETE_RECORD = exports.ADD_SUBSCRIPTION = exports.ADD_RECORDS = exports.ADD_RECORD = void 0;
5
5
  const SET_RECORDS = 'SET_RECORDS';
6
6
  exports.SET_RECORDS = SET_RECORDS;
7
7
  const ADD_RECORD = 'ADD_RECORD';
@@ -19,16 +19,4 @@ exports.SET_SUBSCRIPTIONS = SET_SUBSCRIPTIONS;
19
19
  const ADD_SUBSCRIPTION = 'ADD_SUBSCRIPTION';
20
20
  exports.ADD_SUBSCRIPTION = ADD_SUBSCRIPTION;
21
21
  const DELETE_SUBSCRIPTION = 'DELETE_SUBSCRIPTION';
22
- exports.DELETE_SUBSCRIPTION = DELETE_SUBSCRIPTION;
23
- const SET_MODEL = 'SET_MODEL';
24
- exports.SET_MODEL = SET_MODEL;
25
- const SET_TOKEN = 'SET_TOKEN';
26
- exports.SET_TOKEN = SET_TOKEN;
27
- const SET_COOKIE = 'SET_COOKIE';
28
- exports.SET_COOKIE = SET_COOKIE;
29
- const DELETE_MODEL = 'DELETE_MODEL';
30
- exports.DELETE_MODEL = DELETE_MODEL;
31
- const DELETE_TOKEN = 'DELETE_TOKEN';
32
- exports.DELETE_TOKEN = DELETE_TOKEN;
33
- const DELETE_COOKIE = 'DELETE_COOKIE';
34
- exports.DELETE_COOKIE = DELETE_COOKIE;
22
+ exports.DELETE_SUBSCRIPTION = DELETE_SUBSCRIPTION;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pocketbase-react",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
4
4
  "description": "Unofficial React SDK (React, React Native, Expo) for interacting with the PocketBase JS SDK",
5
5
  "keywords": [
6
6
  "pocketbase",
@@ -8,7 +8,6 @@ import { ClientProvider } from './client';
8
8
  import { ContentProvider } from './content';
9
9
  import { AuthProvider } from './auth';
10
10
  import { StorageService } from '../service/Storage';
11
- import { authAction } from '../store';
12
11
 
13
12
  export const PocketbaseContext = createContext<PocketBase | null>(null);
14
13
 
@@ -22,7 +21,21 @@ export type PocketbaseProviderProps = {
22
21
  };
23
22
 
24
23
  export const Pocketbase = (props: PocketbaseProviderProps) => {
25
- const client = new PocketBase(props.serverURL);
24
+ const [client, setClient] = React.useState<PocketBase | null>(null);
25
+ const [initialCollections, setInitialCollections] = React.useState<string[]>();
26
+ useEffect(() => {
27
+ const client = new PocketBase(props.serverURL);
28
+ client.authStore.onChange(async () => {
29
+ await StorageService.set(StorageService.Constants.COOKIE, client.authStore.exportToCookie());
30
+ setInitialCollections(props.initialCollections);
31
+ });
32
+ StorageService.get(StorageService.Constants.COOKIE).then((cookie) => {
33
+ if (cookie) {
34
+ client.authStore.loadFromCookie(cookie);
35
+ }
36
+ setClient(client);
37
+ });
38
+ }, [props.serverURL]);
26
39
 
27
40
  return client ? (
28
41
  <ClientProvider client={client}>
@@ -32,9 +45,7 @@ export const Pocketbase = (props: PocketbaseProviderProps) => {
32
45
  webRedirectUrl={props.webRedirectUrl}
33
46
  mobileRedirectUrl={props.mobileRedirectUrl}
34
47
  openURL={props.openURL}>
35
- <ContentProvider collections={props.initialCollections}>
36
- {props.children}
37
- </ContentProvider>
48
+ <ContentProvider collections={initialCollections}>{props.children}</ContentProvider>
38
49
  </AuthProvider>
39
50
  </PersistGate>
40
51
  </Provider>
@@ -1,10 +1,7 @@
1
- import AsyncStorage from '@react-native-async-storage/async-storage';
2
- import { Admin, User } from '@tobicrain/pocketbase';
3
1
  import * as React from 'react';
4
- import { createContext, useEffect } from 'react';
2
+ import { createContext } from 'react';
5
3
  import { useClientContext } from '../hooks/useClientContext';
6
4
  import { StorageService } from '../service/Storage';
7
- import { authAction, store, useAppDispatch, useAppSelector } from '../store';
8
5
 
9
6
  export type AuthProviderInfo = {
10
7
  name: string;
@@ -109,32 +106,13 @@ export const AuthProvider = (props: AuthProviderProps) => {
109
106
  await client?.users.delete(id);
110
107
  },
111
108
  };
112
- const dispatch = useAppDispatch;
113
- const selector = useAppSelector((state) => state.reducer.auth);
114
109
 
115
110
  React.useEffect(() => {
116
- const listener = client?.authStore.onChange(() => {
117
- const cookie = client?.authStore.exportToCookie();
118
- if (cookie) dispatch(authAction.setCookie(cookie));
119
- });
120
-
121
111
  (async () => {
122
112
  const methods = await client?.users.listAuthMethods();
123
113
  setAuthProviders(methods?.authProviders);
124
114
  })();
125
-
126
- return () => {
127
- if (listener) listener();
128
- };
129
115
  }, [props.webRedirectUrl, props.mobileRedirectUrl]);
130
116
 
131
- React.useEffect(() => {
132
- const cookie = selector.cookie;
133
- if (cookie) {
134
- console.log('cookie', cookie);
135
- client?.authStore.loadFromCookie(cookie);
136
- }
137
- }, [selector.cookie]);
138
-
139
117
  return <AuthContext.Provider value={actions}>{props.children}</AuthContext.Provider>;
140
118
  };
@@ -3,6 +3,7 @@ import * as store from '../store';
3
3
  import { ContentContext } from '../context';
4
4
  import { Record } from '../interfaces/Record';
5
5
  import { StorageService } from '../service/Storage';
6
+ import { useAppSelector } from '../store';
6
7
 
7
8
  export type SubscribeType = () => Promise<void | undefined>;
8
9
  export type UnsubscribeType = () => Promise<void | undefined>;
@@ -24,9 +25,8 @@ export function useAppContent<T extends Record>(
24
25
  collectionName: string,
25
26
  initialFetch: boolean = false
26
27
  ): { records: T[]; actions: Actions; isSubscribed: boolean } {
27
- const records = (store.useAppSelector((state) => state.reducer.records[collectionName]) ??
28
- []) as T[];
29
- const subscriptions = store.useAppSelector((state) => state.reducer.subscriptions).subscriptions;
28
+ const records = useAppSelector((state) => state.reducer.records[collectionName]) as T[];
29
+ const subscriptions = useAppSelector((state) => state.reducer.subscriptions);
30
30
  const context = useContext(ContentContext);
31
31
 
32
32
  useEffect(() => {
@@ -1,5 +1,4 @@
1
1
  import * as recordsAction from './records';
2
2
  import * as subscriptionsAction from './subscriptions';
3
- import * as authAction from './auth';
4
3
 
5
- export { recordsAction, subscriptionsAction, authAction };
4
+ export { recordsAction, subscriptionsAction };
@@ -1,16 +1,10 @@
1
1
  import { combineReducers } from 'redux';
2
2
  import { records } from './records';
3
3
  import { subscriptions } from './subscriptions';
4
- import { auth } from './auth';
5
4
 
6
5
  export const appReducer = combineReducers({
7
- records: records,
8
- subscriptions: subscriptions,
9
- auth: auth,
6
+ records,
7
+ subscriptions,
10
8
  });
11
9
 
12
- interface AppReducer {
13
- records: ReturnType<typeof appReducer>;
14
- }
15
-
16
- export type State = AppReducer;
10
+ export type State = ReturnType<typeof appReducer>;
@@ -1,46 +1,29 @@
1
1
  import * as ReduxType from '../types';
2
2
 
3
- export interface ReduxSubscriptions {
4
- subscriptions: string[];
5
- }
6
-
7
3
  export type SubscriptionAction = {
8
4
  type: ReduxType.SubscriptionsTypes;
9
5
  payload: string | string[];
10
6
  };
11
7
 
12
8
  function appendSubscription(subscription: string, subscriptions: string[]): string[] {
13
- return [...subscriptions, subscription];
9
+ return subscriptions.includes(subscription) ? subscriptions : [...subscriptions, subscription];
14
10
  }
15
11
 
16
12
  function deleteSubscription(subscription: string, subscriptions: string[]): string[] {
17
13
  return subscriptions.filter((sub) => sub !== subscription);
18
14
  }
19
15
 
20
- export const subscriptions = (
21
- state: ReduxSubscriptions = {
22
- subscriptions: [],
23
- },
24
- action: SubscriptionAction
25
- ) => {
26
- const list = state.subscriptions;
27
-
16
+ export const subscriptions = (state: string[] = [], action: SubscriptionAction) => {
28
17
  switch (action.type) {
29
18
  case ReduxType.SET_SUBSCRIPTIONS:
30
19
  if (Array.isArray(action.payload)) {
31
- return {
32
- subscriptions: action.payload,
33
- };
20
+ return action.payload as string[];
34
21
  }
35
22
  case ReduxType.ADD_SUBSCRIPTION:
36
- return {
37
- subscriptions: appendSubscription(action.payload as string, list),
38
- };
23
+ return appendSubscription(action.payload as string, state) as string[];
39
24
  case ReduxType.DELETE_SUBSCRIPTION:
40
- return {
41
- subscriptions: deleteSubscription(action.payload as string, list),
42
- };
25
+ return deleteSubscription(action.payload as string, state) as string[];
43
26
  default:
44
- return state;
27
+ return state as string[];
45
28
  }
46
29
  };
@@ -21,18 +21,3 @@ export type SubscriptionsTypes =
21
21
  | typeof SET_SUBSCRIPTIONS
22
22
  | typeof ADD_SUBSCRIPTION
23
23
  | typeof DELETE_SUBSCRIPTION;
24
-
25
- export const SET_MODEL = 'SET_MODEL';
26
- export const SET_TOKEN = 'SET_TOKEN';
27
- export const SET_COOKIE = 'SET_COOKIE';
28
- export const DELETE_MODEL = 'DELETE_MODEL';
29
- export const DELETE_TOKEN = 'DELETE_TOKEN';
30
- export const DELETE_COOKIE = 'DELETE_COOKIE';
31
-
32
- export type AuthTypes =
33
- | typeof SET_MODEL
34
- | typeof SET_TOKEN
35
- | typeof DELETE_MODEL
36
- | typeof DELETE_TOKEN
37
- | typeof SET_COOKIE
38
- | typeof DELETE_COOKIE;
@@ -1,23 +0,0 @@
1
- import PocketBase from '@tobicrain/pocketbase';
2
- export declare class AuthenticationService {
3
- private client;
4
- redirect_url: string;
5
- constructor(client: PocketBase);
6
- getListAuthMethods(): Promise<{
7
- [key: string]: any;
8
- emailPassword: boolean;
9
- authProviders: {
10
- name: string;
11
- state: string;
12
- codeVerifier: string;
13
- codeChallenge: string;
14
- codeChallengeMethod: string;
15
- authUrl: string;
16
- }[];
17
- }>;
18
- getDataAuth(): Promise<void>;
19
- AuthWithOauth(provider: string, code: string, verifier: string): Promise<void>;
20
- AuthWithEmail(email: string, password: string): Promise<void>;
21
- RegisterWithEmail(email: string, password: string): Promise<void>;
22
- getUserData(id: string, token: string): Promise<import("@tobicrain/pocketbase").User>;
23
- }
@@ -1,32 +0,0 @@
1
- export class AuthenticationService {
2
- constructor(client) {
3
- this.client = void 0;
4
- this.redirect_url = void 0;
5
- this.client = client;
6
- this.redirect_url = '';
7
- }
8
- async getListAuthMethods() {
9
- return await this.client.users.listAuthMethods();
10
- }
11
- async getDataAuth() {
12
- await this.client.users.authViaOAuth2('google', 'CODE', 'VERIFIER', 'REDIRECT_URL');
13
- }
14
- async AuthWithOauth(provider, code, verifier) {
15
- await this.client.users.authViaOAuth2(provider, code, verifier, this.redirect_url);
16
- }
17
- async AuthWithEmail(email, password) {
18
- await this.client.users.authViaEmail(email, password);
19
- }
20
- async RegisterWithEmail(email, password) {
21
- await this.client.users.create({
22
- email: email,
23
- password: password,
24
- passwordConfirm: password
25
- });
26
- }
27
- async getUserData(id, token) {
28
- const headers = new Headers();
29
- headers.append('Authorization', 'user ' + token);
30
- return await this.client.users.getOne(id);
31
- }
32
- }
@@ -1,9 +0,0 @@
1
- import { Admin, User } from '@tobicrain/pocketbase';
2
- import { AuthAction } from '../reducers/auth';
3
- declare const setToken: (payload: string) => AuthAction;
4
- declare const setModel: (payload: User | Admin | null | string) => AuthAction;
5
- declare const setCookie: (payload: string) => AuthAction;
6
- declare const deleteToken: () => AuthAction;
7
- declare const deleteModel: () => AuthAction;
8
- declare const deleteCookie: () => AuthAction;
9
- export { setToken, setModel, setCookie, deleteToken, deleteModel, deleteCookie };
@@ -1,26 +0,0 @@
1
- import * as ReduxType from '../types';
2
- const setToken = payload => ({
3
- type: ReduxType.SET_TOKEN,
4
- payload
5
- });
6
- const setModel = payload => ({
7
- type: ReduxType.SET_MODEL,
8
- payload
9
- });
10
- const setCookie = payload => ({
11
- type: ReduxType.SET_COOKIE,
12
- payload
13
- });
14
- const deleteToken = () => ({
15
- type: ReduxType.DELETE_TOKEN,
16
- payload: ''
17
- });
18
- const deleteModel = () => ({
19
- type: ReduxType.DELETE_MODEL,
20
- payload: ''
21
- });
22
- const deleteCookie = () => ({
23
- type: ReduxType.DELETE_COOKIE,
24
- payload: ''
25
- });
26
- export { setToken, setModel, setCookie, deleteToken, deleteModel, deleteCookie };
@@ -1,12 +0,0 @@
1
- import { Admin, User } from '@tobicrain/pocketbase';
2
- import * as ReduxType from '../types';
3
- export interface ReduxAuth {
4
- token: string;
5
- model: User | Admin | null;
6
- cookie: string | null;
7
- }
8
- export declare type AuthAction = {
9
- type: ReduxType.AuthTypes;
10
- payload: User | Admin | null | string;
11
- };
12
- export declare const auth: (state: ReduxAuth | undefined, action: AuthAction) => ReduxAuth;
@@ -1,36 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import * as ReduxType from '../types';
3
- export const auth = (state = {
4
- model: null,
5
- token: '',
6
- cookie: null
7
- }, action) => {
8
- switch (action.type) {
9
- case ReduxType.SET_TOKEN:
10
- return _extends({}, state, {
11
- token: action.payload
12
- });
13
- case ReduxType.SET_MODEL:
14
- return _extends({}, state, {
15
- model: action.payload
16
- });
17
- case ReduxType.SET_COOKIE:
18
- return _extends({}, state, {
19
- cookie: action.payload
20
- });
21
- case ReduxType.DELETE_TOKEN:
22
- return _extends({}, state, {
23
- token: ''
24
- });
25
- case ReduxType.DELETE_MODEL:
26
- return _extends({}, state, {
27
- model: null
28
- });
29
- case ReduxType.DELETE_COOKIE:
30
- return _extends({}, state, {
31
- cookie: null
32
- });
33
- default:
34
- return state;
35
- }
36
- };
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.AuthenticationService = void 0;
5
- class AuthenticationService {
6
- constructor(client) {
7
- this.client = void 0;
8
- this.redirect_url = void 0;
9
- this.client = client;
10
- this.redirect_url = '';
11
- }
12
- async getListAuthMethods() {
13
- return await this.client.users.listAuthMethods();
14
- }
15
- async getDataAuth() {
16
- await this.client.users.authViaOAuth2('google', 'CODE', 'VERIFIER', 'REDIRECT_URL');
17
- }
18
- async AuthWithOauth(provider, code, verifier) {
19
- await this.client.users.authViaOAuth2(provider, code, verifier, this.redirect_url);
20
- }
21
- async AuthWithEmail(email, password) {
22
- await this.client.users.authViaEmail(email, password);
23
- }
24
- async RegisterWithEmail(email, password) {
25
- await this.client.users.create({
26
- email: email,
27
- password: password,
28
- passwordConfirm: password
29
- });
30
- }
31
- async getUserData(id, token) {
32
- const headers = new Headers();
33
- headers.append('Authorization', 'user ' + token);
34
- return await this.client.users.getOne(id);
35
- }
36
- }
37
- exports.AuthenticationService = AuthenticationService;
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.setToken = exports.setModel = exports.setCookie = exports.deleteToken = exports.deleteModel = exports.deleteCookie = void 0;
5
- var ReduxType = _interopRequireWildcard(require("../types"));
6
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
7
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
8
- const setToken = payload => ({
9
- type: ReduxType.SET_TOKEN,
10
- payload
11
- });
12
- exports.setToken = setToken;
13
- const setModel = payload => ({
14
- type: ReduxType.SET_MODEL,
15
- payload
16
- });
17
- exports.setModel = setModel;
18
- const setCookie = payload => ({
19
- type: ReduxType.SET_COOKIE,
20
- payload
21
- });
22
- exports.setCookie = setCookie;
23
- const deleteToken = () => ({
24
- type: ReduxType.DELETE_TOKEN,
25
- payload: ''
26
- });
27
- exports.deleteToken = deleteToken;
28
- const deleteModel = () => ({
29
- type: ReduxType.DELETE_MODEL,
30
- payload: ''
31
- });
32
- exports.deleteModel = deleteModel;
33
- const deleteCookie = () => ({
34
- type: ReduxType.DELETE_COOKIE,
35
- payload: ''
36
- });
37
- exports.deleteCookie = deleteCookie;
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- exports.__esModule = true;
5
- exports.auth = void 0;
6
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
7
- var ReduxType = _interopRequireWildcard(require("../types"));
8
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
9
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
10
- const auth = (state = {
11
- model: null,
12
- token: '',
13
- cookie: null
14
- }, action) => {
15
- switch (action.type) {
16
- case ReduxType.SET_TOKEN:
17
- return (0, _extends2.default)({}, state, {
18
- token: action.payload
19
- });
20
- case ReduxType.SET_MODEL:
21
- return (0, _extends2.default)({}, state, {
22
- model: action.payload
23
- });
24
- case ReduxType.SET_COOKIE:
25
- return (0, _extends2.default)({}, state, {
26
- cookie: action.payload
27
- });
28
- case ReduxType.DELETE_TOKEN:
29
- return (0, _extends2.default)({}, state, {
30
- token: ''
31
- });
32
- case ReduxType.DELETE_MODEL:
33
- return (0, _extends2.default)({}, state, {
34
- model: null
35
- });
36
- case ReduxType.DELETE_COOKIE:
37
- return (0, _extends2.default)({}, state, {
38
- cookie: null
39
- });
40
- default:
41
- return state;
42
- }
43
- };
44
- exports.auth = auth;
@@ -1,40 +0,0 @@
1
- import PocketBase from '@tobicrain/pocketbase';
2
-
3
- export class AuthenticationService {
4
- private client: PocketBase;
5
- public redirect_url: string;
6
-
7
- constructor(client: PocketBase) {
8
- this.client = client;
9
- this.redirect_url = '';
10
- }
11
-
12
- async getListAuthMethods() {
13
- return await this.client.users.listAuthMethods();
14
- }
15
-
16
- async getDataAuth() {
17
- await this.client.users.authViaOAuth2('google', 'CODE', 'VERIFIER', 'REDIRECT_URL');
18
- }
19
- async AuthWithOauth(provider: string, code: string, verifier: string) {
20
- await this.client.users.authViaOAuth2(provider, code, verifier, this.redirect_url);
21
- }
22
-
23
- async AuthWithEmail(email: string, password: string) {
24
- await this.client.users.authViaEmail(email, password);
25
- }
26
-
27
- async RegisterWithEmail(email: string, password: string) {
28
- await this.client.users.create({
29
- email: email,
30
- password: password,
31
- passwordConfirm: password,
32
- });
33
- }
34
-
35
- async getUserData(id: string, token: string) {
36
- const headers = new Headers();
37
- headers.append('Authorization', 'user ' + token);
38
- return await this.client.users.getOne(id);
39
- }
40
- }
@@ -1,41 +0,0 @@
1
- import { Admin, User } from '@tobicrain/pocketbase';
2
- import { AuthAction } from '../reducers/auth';
3
- import * as ReduxType from '../types';
4
-
5
- const setToken = (payload: string) =>
6
- ({
7
- type: ReduxType.SET_TOKEN,
8
- payload,
9
- } as AuthAction);
10
-
11
- const setModel = (payload: User | Admin | null | string) =>
12
- ({
13
- type: ReduxType.SET_MODEL,
14
- payload,
15
- } as AuthAction);
16
-
17
- const setCookie = (payload: string) =>
18
- ({
19
- type: ReduxType.SET_COOKIE,
20
- payload,
21
- } as AuthAction);
22
-
23
- const deleteToken = () =>
24
- ({
25
- type: ReduxType.DELETE_TOKEN,
26
- payload: '',
27
- } as AuthAction);
28
-
29
- const deleteModel = () =>
30
- ({
31
- type: ReduxType.DELETE_MODEL,
32
- payload: '',
33
- } as AuthAction);
34
-
35
- const deleteCookie = () =>
36
- ({
37
- type: ReduxType.DELETE_COOKIE,
38
- payload: '',
39
- } as AuthAction);
40
-
41
- export { setToken, setModel, setCookie, deleteToken, deleteModel, deleteCookie };