react native - Listening for Auth Success From Realm Sync Server -
i'm playing around realm , realm object server , i've got things working structure of blocking me. i'm performing basic login so:
realm.sync.user.login('http://ipaddress:9080', 'user', 'password', (error, user) => { if (!error) { console.log('success'); } else { console.log(error); } });
i know can create new realm object schema , sync config within closure. however, since want use realm object throughout application, i'd want auth process 1 step , once successful, create/get realm object can use throughout rest of application, including listening events.
if had sort of structure so...
- src -- realm ---- auth.js // auth ---- index.js // exports realm object -- app.js - index.ios.js - index.android.js
with app.js
being main entry point application, i'd want set state on changes when login successful, can allow other parts of application available. don't want auth code directly inside app.js
; i'd rather import that.
any suggestions?
this looks more general question nodejs server patterns. read, need sort of state established before starting actual application (in case, opened realm).
i recommend exporting function auth.js
returns promise returns realm object. can cached within auth.js in order eliminate re-authenticating , re-opening realm everytime requested.
in app.js
, you'll need call method whenever need realm. can done before server initialization or whenever realm needed after initialization.
Comments
Post a Comment