0.0.6 • Published 7 years ago
cat-session v0.0.6
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}loginorurls.loginlogOff()- log offregister(data)- POST request to${serverUrl}registerorurls.registerupdateProfile(data)- PUT request to${serverUrl}profileorurls.profileuploadProfileImage(image)- POST request to${serverUrl}upload/imageorurls.upload, uploaded as form/multipartlocate(coords)- PUT request to${serverUrl}locateorurls.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