Skip to content

Instantly share code, notes, and snippets.

@dgski
Last active July 26, 2022 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgski/efe7b6afee1c0a9b0887e33f6ae92adb to your computer and use it in GitHub Desktop.
Save dgski/efe7b6afee1c0a9b0887e33f6ae92adb to your computer and use it in GitHub Desktop.
let request = {
"first_name": first_name,
"last_name": last_name,
"email": email,
"address": JSON.parse(address),
"weight_kg": weight_kg,
"target_weight_kg": target_weight_kg,
"height_cm": height_cm,
"activity_level": activity_level,
"gender": gender,
"birthdate": birthday,
"allergies": JSON.parse(allergies),
"diet_preferences": JSON.parse(diet_preferences),
"meals_per_day": meals_per_day,
"phone_number": phone_number,
"password": password
}
performRequest('POST', '/user/create', {
'Accept': 'application/json',
'Content-Type': 'application/json'
}, JSON.stringify(request))
.then(r => {
if(!r.ok) {
alert("Could not create account!");
console.log(r.text())
return;
}
return performRequest('POST', `/user/token`,
{
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
},
`grant_type=password&username=${email}&password=${password}`)
})
.then(r => {
if(!r.ok) {
alert("Could not login to new user account")
return;
}
return r.json();
})
.then(j => {
setAccessToken(j['access_token'])
navigateTo('/')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment