[O] Move cookies detection to login class

This commit is contained in:
Hykilpikonna
2019-09-07 12:14:57 -04:00
parent bd8d7fd113
commit 7af20f806b
2 changed files with 17 additions and 11 deletions
-10
View File
@@ -59,16 +59,6 @@ export default class App extends Vue
{ {
// Show splash // Show splash
console.log(Constants.SPLASH); console.log(Constants.SPLASH);
// Check login cookies
if (this.$cookies.isKey('va.token'))
{
// Hide login
this.showLogin = false;
// Load data
this.loadAfterLogin();
}
} }
/** /**
+17 -1
View File
@@ -15,6 +15,19 @@ export default class Login extends Vue
public loading: boolean = false; public loading: boolean = false;
public error: String = ''; public error: String = '';
/**
* This is called when the instance is created.
*/
public created()
{
// Check login cookies
if (this.$cookies.isKey('va.token'))
{
// Already contains valid token / TODO: Validate
this.$emit('login:token', this.$cookies.get('va.token'));
}
}
/** /**
* On click, sends username and password to the server. * On click, sends username and password to the server.
*/ */
@@ -37,7 +50,10 @@ export default class Login extends Vue
// Check success // Check success
if (response.success) if (response.success)
{ {
// Call custom event with courses info // Save token to cookies
this.$cookies.set('va.token', response.data, '7d');
// Call custom event with token
this.$emit('login:token', response.data); this.$emit('login:token', response.data);
} }
else else