Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@action async login(loginParams: LoginParams): Promise {
const clientIdentifier = await this.getClientIdentifier()
const auth = await this.performLogin(loginParams, clientIdentifier)
// eslint-disable-next-line lodash/prefer-lodash-method
if (auth && auth.data && auth.data.authToken) {
// eslint-disable-next-line lodash/prefer-lodash-typecheck
if (typeof auth.data.authToken === 'string') {
this.devices = await this.fetchDevices(auth.data.authToken)
await AsyncStorage.setItem('loginParams', JSON.stringify(loginParams))
this.isLoggedIn = true
if (this.devices.length === 1) {
appState.connect(this.devices[0])
}
}
}
}
function reducer(state = initialState, action = {}) {
const { type, payload } = action
switch (type) {
case types.SET_STATUS_INPUT:
console.log(payload.text)
return { ...state, statusInput: payload.text }
case types.REPLY_TO:
return { ...state, replyTo: payload.status }
case types.SET_ACCESS_TOKEN:
AsyncStorage.setItem("ACCESS_TOKEN", JSON.stringify(payload))
api.configure(payload.host, payload.accessToken)
return { ...state, host: payload.host, accessToken: payload.accessToken }
case types.SET_ROUTE:
return { ...state, route: payload.route }
case types.UPDATE_STATUS: {
let statuses = { ...state.statuses }
const { status } = payload
const replace = (oldList) => {
const list = oldList.slice()
const i = list.findIndex(x => x.id === status.id)
if (i > -1) {
list[i] = status
}
@action async getClientIdentifier(): Promise {
const value = await AsyncStorage.getItem('X-Plex-Client-Identifier')
if (value) { return value }
const newValue = UUID.v4()
await AsyncStorage.setItem('X-Plex-Client-Identifier', newValue)
return newValue
}