-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
41 lines (35 loc) · 1.05 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { AsyncStorage } from 'react-native'
export const login = async (username, password) => {
const response = await fetch('http://localhost:8000', {
method: 'POST',
headers: {'content-type': 'application/json'},
body: JSON.stringify({username, password}),
})
if (response.ok) {
const {token} = await response.json()
return token
}
const errMessage = await response.text()
throw new Error(errMessage)
}
export const _storeUserid = async (userid) => {
try {
await AsyncStorage.setItem('userid', userid)
console.log(`user id succesfully stored : ${userid}`)
} catch (error) {
console.log(`Error in api.js _storeUserid: ${error}`)
}
}
export const _retrieveUserid = async () => {
try {
const value = await AsyncStorage.getItem('userid')
if (value !== null) {
console.log(`user retireved id: ${value}`)
} else {
console.log(`value is null : ${value}`)
}
return value
} catch (error) {
console.log(`Error in api.js _retrieveUserid: ${error}`)
}
}