const defaultUser = { email: 'titan@hadiyan.net', avatarUrl: 'https://js.devexpress.com/Demos/WidgetsGallery/JSDemos/images/employees/06.png' }; export default { _user: defaultUser, loggedIn() { return !!this._user; }, async logIn(email, password) { try { // Send request console.log(email, password); // this._user = { ...defaultUser, email }; // return { // isOk: true, // data: this._user // }; const requestOptions = { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email: email, password: password }), }; const response = await fetch('http://localhost:9090/api/authentication/login', requestOptions); const data = await response.json(); console.log(data); //console.log(data.data.length); // this._user = { // id: response.data.id, // email: response.data.role, // name: response.data.keterangan, // role_id: response.data.id, // }; if(data.status == 'sukses') { const defaultUser = { email: data.data.email, avatarUrl: 'https://js.devexpress.com/Demos/WidgetsGallery/JSDemos/images/employees/06.png', name: data.data.name, }; this._user = { ...defaultUser }; return { isOk: true, data: this._user }; } else { //--- jika gagal munculkan pesan gagal return { isOk: false, message: "Authentication failed" }; } } catch { return { isOk: false, message: "Authentication failed" }; } }, async logOut() { this._user = null; }, async getUser() { try { // Send request return { isOk: true, data: this._user }; } catch { return { isOk: false }; } }, async resetPassword(email) { try { // Send request console.log(email); return { isOk: true }; } catch { return { isOk: false, message: "Failed to reset password" }; } }, async changePassword(email, recoveryCode) { try { // Send request console.log(email, recoveryCode); return { isOk: true }; } catch { return { isOk: false, message: "Failed to change password" } } }, async createAccount(email, password) { try { // Send request console.log(email, password); return { isOk: true }; } catch { return { isOk: false, message: "Failed to create account" }; } } };