diff --git a/front/API.ts b/front/API.ts index 96056f7..a87088c 100644 --- a/front/API.ts +++ b/front/API.ts @@ -14,12 +14,13 @@ import { useQuery, QueryClient } from "react-query"; type AuthenticationInput = { username: string; password: string }; type RegistrationInput = AuthenticationInput & { email: string }; + export type AccessToken = string; type FetchParams = { route: string; body?: Object; - method?: "GET" | "POST" | "DELETE"; + method?: "GET" | "POST" | "DELETE" | "PATCH" | "PUT"; // If true, No JSON parsing is done, the raw response's content is returned raw?: true; }; @@ -500,12 +501,15 @@ export default class API { } else return reject("wrong email"); }); } else if (dataKey == 'password') { - this.getRequest('http://localhost:3000/users/24').then((res) => { - if (res.password == oldValue) { - this.patchRequest('http://localhost:3000/users/24', {'password': newValue}).finally(() => { + API.fetch({route: '/auth/me'}).then((res) => { + API.fetch({ + route: '/auth/me', + method: 'PATCH', + body: {'password': newValue}}).then(() => { return resolve('password successfully changed'); + }).catch((err) => { + return reject('something went wrong: unable to update the password'); }); - } else return reject("wrong password"); }); } } catch (error) { diff --git a/front/yarn.lock b/front/yarn.lock index 8d52035..f459993 100644 --- a/front/yarn.lock +++ b/front/yarn.lock @@ -4395,6 +4395,18 @@ dependencies: "@babel/types" "^7.3.0" +"@types/bcrypt@^5.0.0": + version "5.0.0" + resolved "https://registry.yarnpkg.com/@types/bcrypt/-/bcrypt-5.0.0.tgz#a835afa2882d165aff5690893db314eaa98b9f20" + integrity sha512-agtcFKaruL8TmcvqbndlqHPSJgsolhf/qPWchFlgnW1gECTN/nKbFcoFnvKAQRFfKbh+BO6A3SWdJu9t+xF3Lw== + dependencies: + "@types/node" "*" + +"@types/bcryptjs@^2.4.2": + version "2.4.2" + resolved "https://registry.yarnpkg.com/@types/bcryptjs/-/bcryptjs-2.4.2.tgz#e3530eac9dd136bfdfb0e43df2c4c5ce1f77dfae" + integrity sha512-LiMQ6EOPob/4yUL66SZzu6Yh77cbzJFYll+ZfaPiPPFswtIlA/Fs1MzdKYA7JApHU49zQTbJGX3PDmCpIdDBRQ== + "@types/cacheable-request@^6.0.1": version "6.0.3" resolved "https://registry.yarnpkg.com/@types/cacheable-request/-/cacheable-request-6.0.3.tgz#a430b3260466ca7b5ca5bfd735693b36e7a9d183" @@ -5954,6 +5966,11 @@ batch@0.6.1: resolved "https://registry.yarnpkg.com/batch/-/batch-0.6.1.tgz#dc34314f4e679318093fc760272525f94bf25c16" integrity sha512-x+VAiMRL6UPkx+kudNvxTl6hB2XNNCG2r+7wixVfIYwu/2HKRXimwQyaumLjMveWvT2Hkd/cAJw+QBMfJ/EKVw== +bcryptjs@^2.4.3: + version "2.4.3" + resolved "https://registry.yarnpkg.com/bcryptjs/-/bcryptjs-2.4.3.tgz#9ab5627b93e60621ff7cdac5da9733027df1d0cb" + integrity sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ== + better-opn@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/better-opn/-/better-opn-2.1.1.tgz#94a55b4695dc79288f31d7d0e5f658320759f7c6" @@ -17536,8 +17553,10 @@ watchpack@^1.6.1, watchpack@^1.7.4: resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.7.5.tgz#1267e6c55e0b9b5be44c2023aed5437a2c26c453" integrity sha512-9P3MWk6SrKjHsGkLT2KHXdQ/9SNkyoJbabxnKOoJepsvJjJG8uYTR3yTPxPQvNDI3w4Nz1xnE0TLHK4RIVe/MQ== dependencies: + chokidar "^3.4.1" graceful-fs "^4.1.2" neo-async "^2.5.0" + watchpack-chokidar2 "^2.0.1" optionalDependencies: chokidar "^3.4.1" watchpack-chokidar2 "^2.0.1"