Skip to content
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
15 changes: 5 additions & 10 deletions contentcuration/contentcuration/frontend/shared/data/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,16 +931,11 @@ export const Session = new IndexedDBResource({
async getSession() {
return this.get(CURRENT_USER);
},
async updateSession(currentUser) {
const result = await this.update(CURRENT_USER, currentUser);
if (!result) {
// put takes an object, not keypaths, so if the current user doesn't exist
// we create it with a put, and then call update again.
await this.put({
CURRENT_USER,
});
await this.update(CURRENT_USER, currentUser);
}
setSession(currentUser) {
return this.put({ CURRENT_USER, ...currentUser });
},
updateSession(currentUser) {
return this.update(CURRENT_USER, currentUser);
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { forceServerSync } from 'shared/data/serverSync';
import translator from 'shared/translator';
import { applyMods } from 'shared/data/applyRemoteChanges';

const GUEST_USER = {};

function langCode(language) {
// Turns a Django language name (en-gb) into an ISO language code (en-GB)
// Copied and modified from Django's to_locale function that does something similar
Expand All @@ -30,7 +28,7 @@ function langCode(language) {

export default {
state: () => ({
currentUser: GUEST_USER,
currentUser: {},
preferences:
window.user_preferences === 'string'
? JSON.parse(window.user_preferences)
Expand All @@ -54,7 +52,7 @@ export default {
}
},
REMOVE_SESSION(state) {
state.currentUser = GUEST_USER;
state.currentUser = {};
},
},
getters: {
Expand Down Expand Up @@ -98,9 +96,12 @@ export default {
},
},
actions: {
async saveSession(context, currentUser) {
await Session.updateSession(currentUser);
saveSession(context, currentUser) {
context.commit('ADD_SESSION', currentUser);
// This will trigger the IndexedDB listener to call `ADD_SESSION` if this actually creates
// the user in IndexedDB, but if we've already saved it to IndexedDB, we want to call the
// above `ADD_SESSION` regardless
return Session.setSession(currentUser);
},
login(context, credentials) {
return client.post(window.Urls.login(), credentials);
Expand Down