pocketbase-react 0.1.8 → 0.1.10
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/README.md +57 -7
- package/dist/pocketbase-react.js +104 -24
- package/dist/pocketbase-react.min.js +3 -3
- package/es/context/Pocketbase.d.ts +3 -4
- package/es/context/Pocketbase.js +8 -9
- package/es/context/auth.d.ts +39 -0
- package/es/context/auth.js +67 -0
- package/es/context/index.d.ts +1 -0
- package/es/context/index.js +1 -0
- package/es/hooks/index.d.ts +1 -0
- package/es/hooks/index.js +2 -1
- package/es/hooks/useAuth.d.ts +4 -0
- package/es/hooks/useAuth.js +8 -0
- package/es/service/Authentication.d.ts +23 -0
- package/es/service/Authentication.js +32 -0
- package/es/service/Storage.d.ts +5 -0
- package/es/service/Storage.js +20 -0
- package/es/store/store.js +7 -19
- package/lib/context/Pocketbase.js +7 -8
- package/lib/context/auth.js +74 -0
- package/lib/context/index.js +11 -0
- package/lib/hooks/index.js +11 -0
- package/lib/hooks/useAuth.js +12 -0
- package/lib/service/Authentication.js +37 -0
- package/lib/service/Storage.js +26 -0
- package/lib/store/store.js +7 -19
- package/package.json +1 -1
- package/src/context/Pocketbase.tsx +10 -14
- package/src/context/auth.tsx +114 -0
- package/src/context/index.ts +2 -1
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useAuth.ts +7 -0
- package/src/service/Authentication.ts +50 -0
- package/src/service/Storage.ts +23 -0
- package/src/store/store.tsx +7 -21
package/src/context/index.ts
CHANGED
package/src/hooks/index.ts
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
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(
|
|
18
|
+
'google',
|
|
19
|
+
'CODE',
|
|
20
|
+
'VERIFIER',
|
|
21
|
+
'REDIRECT_URL'
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
async AuthWithOauth(provider: string, code: string, verifier: string) {
|
|
25
|
+
await this.client.users.authViaOAuth2(
|
|
26
|
+
provider,
|
|
27
|
+
code,
|
|
28
|
+
verifier,
|
|
29
|
+
this.redirect_url
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async AuthWithEmail(email: string, password: string){
|
|
34
|
+
await this.client.users.authViaEmail(email, password);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async RegisterWithEmail(email: string, password: string){
|
|
38
|
+
await this.client.users.create({
|
|
39
|
+
email: email,
|
|
40
|
+
password: password,
|
|
41
|
+
passwordConfirm: password,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async getUserData(id:string, token:string) {
|
|
46
|
+
const headers = new Headers()
|
|
47
|
+
headers.append("Authorization","user "+token)
|
|
48
|
+
return await this.client.users.getOne(id)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
2
|
+
|
|
3
|
+
export class StorageService {
|
|
4
|
+
static async get(key: string): Promise<string | null> {
|
|
5
|
+
return typeof document !== 'undefined' ? localStorage.getItem(key) : await AsyncStorage.getItem(key);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static async set(key: string, value: string): Promise<void> {
|
|
9
|
+
if (typeof document !== 'undefined') {
|
|
10
|
+
return localStorage.setItem(key, value);
|
|
11
|
+
} else {
|
|
12
|
+
return await AsyncStorage.setItem(key, value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static async remove(key: string): Promise<void> {
|
|
17
|
+
if (typeof document !== 'undefined') {
|
|
18
|
+
return localStorage.removeItem(key);
|
|
19
|
+
} else {
|
|
20
|
+
return await AsyncStorage.removeItem(key);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/store/store.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import { appReducer } from './reducers';
|
|
|
5
5
|
import thunk from 'redux-thunk';
|
|
6
6
|
import { RecordAction } from './reducers/records';
|
|
7
7
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
8
|
+
import { StorageService } from '../service/Storage';
|
|
8
9
|
|
|
9
10
|
interface Storage {
|
|
10
11
|
getItem(key: string, ...args: Array<any>): any;
|
|
@@ -14,29 +15,14 @@ interface Storage {
|
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
const CustomStorage: Storage = {
|
|
17
|
-
getItem: async (
|
|
18
|
-
|
|
19
|
-
return localStorage.getItem(_key);
|
|
20
|
-
}
|
|
21
|
-
else if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
22
|
-
return await AsyncStorage.getItem(_key);
|
|
23
|
-
}
|
|
18
|
+
getItem: async (key: string, ..._args: Array<any>) => {
|
|
19
|
+
return await StorageService.get(key);
|
|
24
20
|
},
|
|
25
|
-
setItem: async (
|
|
26
|
-
|
|
27
|
-
return localStorage.setItem(_key, _value);
|
|
28
|
-
}
|
|
29
|
-
else if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
30
|
-
return await AsyncStorage.setItem(_key, _value);
|
|
31
|
-
}
|
|
21
|
+
setItem: async (key: string, value: any, ..._args: Array<any>) => {
|
|
22
|
+
return StorageService.set(key, value);
|
|
32
23
|
},
|
|
33
|
-
removeItem: async (
|
|
34
|
-
|
|
35
|
-
return localStorage.removeItem(_key);
|
|
36
|
-
}
|
|
37
|
-
else if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
38
|
-
return await AsyncStorage.removeItem(_key);
|
|
39
|
-
}
|
|
24
|
+
removeItem: async (key: string, ..._args: Array<any>) => {
|
|
25
|
+
return StorageService.remove(key);
|
|
40
26
|
},
|
|
41
27
|
};
|
|
42
28
|
|