Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loggingOut as a reactive source #108

Merged
merged 2 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To test on a Real iOS Device, you must build a release archive.

All code-level PRs must be tested on a real device, simulators/emulators are not sufficient.

Ondce you have your testing app installed on a device, use the following test cases depending on what features your update interacts with:
Once you have your testing app installed on a device, use the following test cases depending on what features your update interacts with:

**All Updates:**
- Device with Internet Connection
Expand Down
3 changes: 3 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Gets the current connection status. Returns an object with the following propert
### `Meteor.loggingIn()`
Returns true if attempting to login

### `Meteor.loggingOut()`
Returns true if attempting to logout

### `Meteor.loginWithPassword`

### `Meteor.logout`
Expand Down
2 changes: 2 additions & 0 deletions src/Data.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ export default {
this.ddp.on('connected', cb);
this.ddp.on('disconnected', cb);
this.on('loggingIn', cb);
this.on('loggingOut', cb);
this.on('change', cb);
},
offChange(cb) {
this.db.off('change', cb);
this.ddp.off('connected', cb);
this.ddp.off('disconnected', cb);
this.off('loggingIn', cb);
this.off('loggingOut', cb);
this.off('change', cb);
},
on(eventName, cb) {
Expand Down
6 changes: 5 additions & 1 deletion src/Meteor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ declare module '@meteorrn/core' {
function disconnect(): void;
function reconnect(): void;

type Status = 'change' | 'connected' | 'disconnected' | 'loggingIn' | 'change';
type Status = 'change' | 'connected' | 'disconnected' | 'loggingIn' | 'loggingOut';

function call(...args: any[]): void;
function status(): {
connected: boolean;
status: Status;
};

function logout(callback: (error: any) => void): void;
function loggingOut(): boolean;
function loggingIn(): boolean;

interface Data {
getUrl(): string;
waitDdpReady(cb: (...args: any[]) => void): void;
Expand Down
14 changes: 14 additions & 0 deletions src/user/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ const User = {
return user && user._id;
},
_isLoggingIn: true,
_isLoggingOut: false,
loggingIn() {
return User._isLoggingIn;
},
loggingOut() {
return User._isLoggingOut;
},
logout(callback) {
User._startLoggingOut();
Meteor.call('logout', err => {
User.handleLogout();
Meteor.connect();
Expand All @@ -35,6 +40,7 @@ const User = {
Data._options.AsyncStorage.removeItem(TOKEN_KEY);
Data._tokenIdSaved = null;
User._userIdSaved = null;
User._endLoggingOut();
},
loginWithPassword(selector, password, callback) {
if (typeof selector === 'string') {
Expand Down Expand Up @@ -83,10 +89,18 @@ const User = {
User._isLoggingIn = true;
Data.notify('loggingIn');
},
_startLoggingOut() {
User._isLoggingOut = true;
Data.notify('loggingOut');
},
_endLoggingIn() {
User._isLoggingIn = false;
Data.notify('loggingIn');
},
_endLoggingOut() {
User._isLoggingOut = false;
Data.notify('loggingOut');
},
_handleLoginCallback(err, result) {
if (!err) {
Meteor.isVerbose && console.info("User._handleLoginCallback::: token:", result.token, "id:", result.id);
Expand Down