Skip to content
Merged
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
10 changes: 8 additions & 2 deletions app/services/session.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { debug } from '@ember/debug';
import Service, { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';

Expand Down Expand Up @@ -179,16 +180,21 @@ export default class SessionService extends Service {
});

loadUserTask = dropTask(async () => {
if (!this.isLoggedIn) return {};
if (!this.isLoggedIn) {
debug('User is not logged in, skipping user load');
return {};
}

let response;
try {
response = await ajax('/api/v1/me');
} catch {
} catch (error) {
debug(`Failed to load user: ${error}`);
return {};
}

let currentUser = this.store.push(this.store.normalize('user', response.user));
debug(`User found: ${currentUser.login}`);
let ownedCrates = response.owned_crates.map(c => this.store.push(this.store.normalize('owned-crate', c)));

let { id } = currentUser;
Expand Down
Loading