Skip to content

Commit

Permalink
Make the custom session store slightly less offensive.
Browse files Browse the repository at this point in the history
  • Loading branch information
pngwn committed Jun 12, 2019
1 parent 7ae8a0f commit 7b9b898
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
2 changes: 2 additions & 0 deletions cypress/integration/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('Sapper template app', () => {
cy.contains('h1', 'conduit')
});

// TODO more tests!
it('is possible to change route', () => {
cy.visit('/login');
cy.contains('h1', 'Sign In')
Expand Down Expand Up @@ -43,6 +44,7 @@ describe('Sapper template app', () => {
cy.get(':nth-child(3) > .form-control').type(pw)
cy.get('form').submit()

// cy.visit('/')
cy.contains(usr);
cy.get(':nth-child(3) > .nav-link')
.should('have.attr', 'href')
Expand Down
63 changes: 33 additions & 30 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,42 @@ function post(endpoint, data) {
}).then(r => r.json());
}

const session = () => {
let store;

let store;
return {
set(sessionStore) {
store = sessionStore;
},

export const userSession = {
set(sessionStore) {
store = sessionStore;
},
login(credentials) {
return post(`auth/login`, credentials).then(response => {
if (response.user) store.update(state => ({ ...state, user: response.user }));
return response;
});
},

login(credentials) {
return post(`auth/login`, credentials).then(response => {
if (response.user) store.update(state => ({ ...state, user: response.user }));
return response;
});
},
logout() {
return post(`auth/logout`).then(response => {
store.update(state => ({ ...state, user: null }));
return response;
});
},

logout() {
return post(`auth/logout`).then(response => {
store.update(state => ({ ...state, user: null }));
return response;
});
},
register(user) {
return post(`auth/register`, user).then(response => {
if (response.user) store.update(state => ({ ...state, user: response.user }));
return response;
});
},

register(user) {
return post(`auth/register`, user).then(response => {
if (response.user) store.update(state => ({ ...state, user: response.user }));
return response;
});
},
save(user) {
return post(`auth/save`, user).then(response => {
if (response.user) store.update(state => ({ ...state, user: response.user }));
return response;
});
}
};
}

save(user) {
return post(`auth/save`, user).then(response => {
if (response.user) store.update(state => ({ ...state, user: response.user }));
return response;
});
}
}
export const userSession = session();

0 comments on commit 7b9b898

Please sign in to comment.