Skip to content

Commit 275a42d

Browse files
author
Filip Hric
committed
change token naming
1 parent 345aad5 commit 275a42d

File tree

13 files changed

+42
-42
lines changed

13 files changed

+42
-42
lines changed

cypress/e2e/login.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
describe('Login', () => {
2-
2+
33
const user = {
44
55
password: 'Asdf.1234#'
66
}
77

88
beforeEach(() => {
9-
9+
1010
cy.request('POST', '/api/reset')
11-
cy.signupApi({login: false, ...user})
11+
cy.signupApi({ login: false, ...user })
1212

1313
});
1414

@@ -47,15 +47,15 @@ describe('Login', () => {
4747
cy.location('pathname')
4848
.should('eq', '/')
4949

50-
cy.getCookie('trello_token')
50+
cy.getCookie('auth_token')
5151
.should('exist')
5252

5353
cy.getDataCy('logged-user')
5454
.click()
5555

5656
cy.getDataCy('notification-message')
5757
.should('contain.text', 'User was logged out')
58-
58+
5959
});
6060

6161
it('logs in a user (enter)', () => {
@@ -78,20 +78,20 @@ describe('Login', () => {
7878
cy.location('pathname')
7979
.should('eq', '/')
8080

81-
cy.getCookie('trello_token')
81+
cy.getCookie('auth_token')
8282
.should('exist')
8383

8484
cy.getDataCy('logged-user')
8585
.click()
8686

8787
cy.getDataCy('notification-message')
8888
.should('contain.text', 'User was logged out')
89-
89+
9090
});
9191

9292
it('shows error on invalid login', () => {
9393

94-
cy.setCookie('trello_token', 'invalid')
94+
cy.setCookie('auth_token', 'invalid')
9595

9696
cy.visit('/login')
9797

cypress/e2e/signup.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('Signup', () => {
2525
cy.location('pathname')
2626
.should('eq', '/')
2727

28-
cy.getCookie('trello_token')
28+
cy.getCookie('auth_token')
2929
.should('exist')
3030

3131
});
@@ -48,7 +48,7 @@ describe('Signup', () => {
4848
cy.location('pathname')
4949
.should('eq', '/')
5050

51-
cy.getCookie('trello_token')
51+
cy.getCookie('auth_token')
5252
.should('exist')
5353

5454
});

cypress/support/commands/googleLogin.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export {}
1+
export { }
22
declare global {
33
namespace Cypress {
44
interface Chainable {
@@ -14,9 +14,9 @@ declare global {
1414
*
1515
*/
1616

17-
export const googleLogin = function(this: any): Cypress.Chainable<any> {
17+
export const googleLogin = function (this: any): Cypress.Chainable<any> {
1818

19-
return cy.request({
19+
return cy.request({
2020
method: 'POST',
2121
url: 'https://www.googleapis.com/oauth2/v4/token',
2222
body: {
@@ -27,9 +27,9 @@ return cy.request({
2727
},
2828
}).then(({ body }) => {
2929
const { id_token } = body
30-
cy.request('POST', '/api/login', { jwt: id_token })
31-
.then( ({ body: { accessToken } }) => {
32-
cy.setCookie('trello_token', accessToken)
33-
})
30+
cy.request('POST', '/api/login', { jwt: id_token })
31+
.then(({ body: { accessToken } }) => {
32+
cy.setCookie('auth_token', accessToken)
33+
})
3434
})
3535
}

cypress/support/commands/googleSignup.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export {}
1+
export { }
22
declare global {
33
namespace Cypress {
44
interface Chainable {
@@ -14,9 +14,9 @@ declare global {
1414
*
1515
*/
1616

17-
export const googleSignup = function(this: any): Cypress.Chainable<any> {
17+
export const googleSignup = function (this: any): Cypress.Chainable<any> {
1818

19-
return cy.request({
19+
return cy.request({
2020
method: 'POST',
2121
url: 'https://www.googleapis.com/oauth2/v4/token',
2222
body: {
@@ -27,9 +27,9 @@ return cy.request({
2727
},
2828
}).then(({ body }) => {
2929
const { id_token } = body
30-
cy.request('POST', '/api/signup', { jwt: id_token })
31-
.then( ({ body: { accessToken } }) => {
32-
cy.setCookie('trello_token', accessToken)
33-
})
30+
cy.request('POST', '/api/signup', { jwt: id_token })
31+
.then(({ body: { accessToken } }) => {
32+
cy.setCookie('auth_token', accessToken)
33+
})
3434
})
3535
}

cypress/support/commands/signupApi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export {}
1+
export { }
22
declare global {
33
namespace Cypress {
44
interface Chainable {
@@ -15,13 +15,13 @@ declare global {
1515
* @example
1616
* cy.signupApi({ email: 'filip@example.com', password: 'nbusr123', login: false })
1717
*/
18-
export const signupApi = function(this: any, { email, password, login = true }: { email: string, password: string, login?: boolean }) {
18+
export const signupApi = function (this: any, { email, password, login = true }: { email: string, password: string, login?: boolean }) {
1919

2020
cy
2121
.request('POST', '/api/signup', {
2222
email, password
2323
}).then(({ body }) => {
24-
if (login) cy.setCookie('trello_token', body.accessToken)
24+
if (login) cy.setCookie('auth_token', body.accessToken)
2525
cy.wrap(body).as('user');
2626
});
2727

src/App.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ const toggleTools = state.toggleTools;
2222
const toggleSearch = state.toggleSearch;
2323
const getCookieValue = (name: string) => document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop();
2424
25-
const trelloToken = getCookieValue('trello_token');
26-
const trelloTokenValid = trelloToken?.split('.')[1];
25+
const authToken = getCookieValue('auth_token');
26+
const authTokenValid = authToken?.split('.')[1];
2727
28-
if (trelloToken && !trelloTokenValid) {
28+
if (authToken && !authTokenValid) {
2929
state.showNotification('Invalid authorization', true);
30-
document.cookie = 'trello_token=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
30+
document.cookie = 'auth_token=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
3131
}
3232
33-
if (trelloToken && trelloTokenValid) {
34-
axios.defaults.headers.common['Authorization'] = `Bearer ${trelloToken}`;
35-
const userData = window.atob(trelloTokenValid);
33+
if (authToken && authTokenValid) {
34+
axios.defaults.headers.common['Authorization'] = `Bearer ${authToken}`;
35+
const userData = window.atob(authTokenValid);
3636
const userId = JSON.parse(userData).sub;
3737
state.user(userId);
3838
}

src/components/LoginButton.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const { activeUser } = storeToRefs(useStore());
4747
const logout = function (this: any) {
4848
activeUser.value.loggedIn = false;
4949
axios.defaults.headers.common['Authorization'] = '';
50-
document.cookie = 'trello_token=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
50+
document.cookie = 'auth_token=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
5151
showNotification('User was logged out', false);
5252
};
5353
</script>

src/store/actions/login.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const login = async function (this: any, email: string, password: string)
88
const email = data.user.email;
99
const id = data.user.id;
1010
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
11-
document.cookie = `trello_token=${token}`;
11+
document.cookie = `auth_token=${token}`;
1212
this.activeUser.id = id;
1313
this.activeUser.email = email;
1414
this.activeUser.accessToken = token;

src/store/actions/oauthLogin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ export const oauthLogin = async function (this: any, jwt: string) {
88
const email = data.user.email;
99
const id = data.user.id;
1010
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
11-
document.cookie = `trello_token=${token}`;
11+
document.cookie = `auth_token=${token}`;
1212
this.activeUser.id = id;
1313
this.activeUser.email = email;
1414
this.activeUser.accessToken = token;
1515
this.user(this.activeUser.id);
1616
})
1717
.catch(({ response }) => {
18-
document.cookie = 'trello_token=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
18+
document.cookie = 'auth_token=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
1919
this.showNotification(response.data, true);
2020
});
2121
};

src/store/actions/oauthSignup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const oauthSignup = async function (this: any, jwt: string) {
88
const email = data.user.email;
99
const id = data.user.id;
1010
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
11-
document.cookie = `trello_token=${token}`;
11+
document.cookie = `auth_token=${token}`;
1212
this.activeUser.id = id;
1313
this.activeUser.email = email;
1414
this.activeUser.accessToken = token;

src/store/actions/resetUsers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ export const resetUsers = async function (this: any) {
55
this.activeUser.loggedIn = false;
66
this.activeUser.email = '';
77
axios.defaults.headers.common['Authorization'] = '';
8-
document.cookie = 'trello_token=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
8+
document.cookie = 'auth_token=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
99
this.showNotification('All users were deleted', false);
1010
};

src/store/actions/signup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const signup = async function (this: any, email: string, password: string
88
const email = data.user.email;
99
const id = data.user.id;
1010
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
11-
document.cookie = `trello_token=${token}`;
11+
document.cookie = `auth_token=${token}`;
1212
this.activeUser.id = id;
1313
this.activeUser.email = email;
1414
this.activeUser.accessToken = token;

src/store/actions/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ export const user = async function (this: any, id: number) {
1111
})
1212
.catch(() => {
1313
this.showNotification('User is not authorized', true);
14-
document.cookie = 'trello_token=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
14+
document.cookie = 'auth_token=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
1515
});
1616
};

0 commit comments

Comments
 (0)