[O] Move cookies detection to login class
This commit is contained in:
@@ -59,16 +59,6 @@ export default class App extends Vue
|
||||
{
|
||||
// Show splash
|
||||
console.log(Constants.SPLASH);
|
||||
|
||||
// Check login cookies
|
||||
if (this.$cookies.isKey('va.token'))
|
||||
{
|
||||
// Hide login
|
||||
this.showLogin = false;
|
||||
|
||||
// Load data
|
||||
this.loadAfterLogin();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,19 @@ export default class Login extends Vue
|
||||
public loading: boolean = false;
|
||||
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.
|
||||
*/
|
||||
@@ -37,7 +50,10 @@ export default class Login extends Vue
|
||||
// Check 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);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user