Skip to content
Open
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
14 changes: 8 additions & 6 deletions packages/ember-simple-auth/src/services/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,13 @@ export default class SessionService<Data = DefaultDataShape> extends Service {
@public
*/
setup() {
this._setupIsCalled = true;
this._setupHandlers();

return this.session.restore().catch(() => {
// If it raises an error then it means that restore didn't find any restorable state.
});
if(!this._setupIsCalled) {
this._setupIsCalled = true;
this._setupHandlers();

return this.session.restore().catch(() => {
// If it raises an error then it means that restore didn't find any restorable state.
});
}
Comment on lines +337 to +344
Copy link
Collaborator

@BobrImperator BobrImperator Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR 👍
It seems like one alternative could be to use an instance-initializer instead (thinking out loud).

Could you add a test asserting that _setupHandlers can be called only once?

We might want to make sure that the setupHandlers runs only once while restore continues to be called.

Suggested change
if(!this._setupIsCalled) {
this._setupIsCalled = true;
this._setupHandlers();
return this.session.restore().catch(() => {
// If it raises an error then it means that restore didn't find any restorable state.
});
}
if (!this._setupIsCalled) {
this._setupIsCalled = true;
this._setupHandlers();
}
return this.session.restore().catch(() => {
// If it raises an error then it means that restore didn't find any restorable state.
});

}
}