diff --git a/src/api.ts b/src/api.ts index 51c6a17..a90f107 100644 --- a/src/api.ts +++ b/src/api.ts @@ -45,8 +45,10 @@ class Model { init.headers.set("Accept", "application/json"); init.headers.set("Content-Type", "application/json"); const response = await fetch(`/api/${endpoint}/`, init); - const dataOrErrors: Array = await response.json(); - if (response.status !== 201) { + const dataOrErrors = await response.json(); + if (response.status === 200) { + return dataOrErrors; + } else { throw new APIError(response.statusText, dataOrErrors); } } @@ -58,6 +60,9 @@ interface UserData { } export class User extends Model implements UserData { + public isAuthenticated = false; + private token = ""; + constructor(public email: string, public password: string) { super(); } @@ -67,10 +72,12 @@ export class User extends Model implements UserData { } async login(): Promise { - await Model.create("token/login", { + const response = await Model.create("token/login", { email: this.email, password: this.password, }); + this.token = response.auth_token; + this.isAuthenticated = true; } async signup(): Promise { diff --git a/src/components/LoginForm.vue b/src/components/LoginForm.vue index 85e8a33..11844f0 100644 --- a/src/components/LoginForm.vue +++ b/src/components/LoginForm.vue @@ -1,5 +1,5 @@