This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Before reading: | |
This is a soft auth check. Auth check should always be done server side, if not, your rest api are not checking correctly for auth. | |
1. Auth is in the store. | |
You need to setup constants for AUTH_SET_TOKEN and AUTH_LOGOUT, | |
then create the action creators authSetToken(token) and authLogout() action creators. | |
Then setup a reducer that when AUTH_SET_TOKEN is dispatched, sets the internal state to {token: token}, | |
and when logout is dispatched, clears it. | |
Now setup a utility function isLoggedIn(state) function, that only checks in state.auth.token exists, this is a soft check. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var React = require('react-native'); | |
var {DeviceEventEmitter, View, StyleSheet} = React; | |
var styles = StyleSheet.create({ | |
main: { | |
position: 'absolute', | |
top: 0, | |
left: 0, | |
right: 0 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var React = require('react-native'); | |
var EventEmitter = require('eventemitter3'); | |
var MyTextInput = require('./TextInput'); | |
var {View, Text, TextInput, TouchableOpacity, StyleSheet} = React; | |
var styles = StyleSheet.create({ | |
wrapper: { | |
position: 'absolute', | |
top: 0, | |
left: 0, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// constants.js | |
module.exports = { | |
AUTH_SET_TOKEN: 'auth/SET_TOKEN', | |
AUTH_DISCARD_TOKEN: 'auth/DISCARD_TOKEN', | |
AUTH_SET_USER: 'auth/SET_USER' | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var { | |
AUTH_SET_TOKEN, | |
AUTH_DISCARD_TOKEN, | |
AUTH_SET_USER | |
} = require('./constants'); | |
function authSetToken(token){ | |
return { | |
type: AUTH_SET_TOKEN, | |
token |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var { | |
AUTH_SET_TOKEN, | |
AUTH_DISCARD_TOKEN, | |
AUTH_SET_USER | |
} = require('./constants'); | |
function auth(state = {}, action){ | |
switch(action.type){ | |
// saves the token into the state | |
case AUTH_SET_TOKEN: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var {authDiscardToken} = require('./actions'); | |
var request = require('superagent'); | |
var API_ROOT = 'http://localhost/api'; | |
/* | |
This below is the format the middleware accepts. | |
{ | |
types: [ACT_LOGIN_PENDING, ACT_LOGIN_SUCCESS, ACT_LOGIN_ERROR], | |
url: '/auth/login', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// utility functions for the authLogin | |
function authLoginStart(){ | |
return { | |
type: AUTH_LOGIN_START | |
}; | |
} | |
function authLoginSuccess(user){ | |
return { | |
type: AUTH_LOGIN_SUCCESS, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
import {withEffect} from 'redux-side-effects' | |
// inside your reducer you can do this | |
return withEffect(authUser, (effects) => effects.concat([ | |
routerRedirectAction('/url/action'), | |
otherPossibleActionToDispatch('params') | |
])); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--------- beginning of /dev/log/system | |
I/Vold ( 333): [LGE][VOLD][NetlinkHandler.cpp][onEvent()] subsys:cpu, action:0 | |
V/ActivityManager( 683): Moving to STOPPED: ActivityRecord{4299f7b0 u0 com.lge.launcher2/.Launcher t1} (stop complete) | |
D/NotificationService( 683): updateLightListLocked :r=null, action=2 | |
D/NotificationService( 683): updateLightListLocked :r=NotificationRecord(0x43080ec0: pkg=android user=UserHandle{-1} id=17040542 tag=null score=0: Notification(pri=0 contentView=android/0x1090064 vibrate=null sound=null defaults=0x0 flags=0x2 kind=[android.system.imeswitcher])), action=2 |
OlderNewer