cat-session
v0.0.6
Published
Session manager, actions and reducers for Redux/Immutable
Downloads
2
Readme
Cat Session 🐈 for Redux
Session manager, actions and reducers for Redux/Immutable.
🐱 Installation
npm install -s cat-session
🐱 Configuration
Define custom fields for the session
const sessionDataFields = {
displayName: '',
username: '',
id: null,
profileImage: null,
email: null
}
Add session actions:
import { createSessionActions } from 'cat-session';
const sessionActions = createSessionActions({
dataFields: sessionDataFields,
serverUrl: endpoint
// urls: {} - you can define custom paths for the requests
});
Add session reducers:
import { createSessionStore } from 'cat-session'
const stores = {
session: createSessionStore(sessionDataFields),
...myOtherStores
}
🐱 Usage
Actions
init()
- call it right after your app is started, the session values will be loaded from localStorage (or AsyncStorage for React Native)logIn(data)
- POST request to${serverUrl}login
orurls.login
logOff()
- log offregister(data)
- POST request to${serverUrl}register
orurls.register
updateProfile(data)
- PUT request to${serverUrl}profile
orurls.profile
uploadProfileImage(image)
- POST request to${serverUrl}upload/image
orurls.upload
, uploaded as form/multipartlocate(coords)
- PUT request to${serverUrl}locate
orurls.locate
, should be called on user position changeresetIsJustRegistered()
- resetisJustRegistered
Store fields (all the fields are Immutable values!)
initializing
- true if session data in not available yetloggedIn
- true if user is logged inloggingIn
- true if user is logging in or registeringtoken
- session JWTuploadProgress
- profile image upload progress in percentisUploadingProfileImage
- true during profile image uploadisJustRegistered
- true after registration completed, could be reseted by callingresetIsJustRegistered()
error
- text value with login/registration error ('loginErrorUnauthorized', 'loginErrorForbidden', 'loginError')- ALL THE FIELDS FROM
sessionDataFields