helo :)
I'm trying to register an user and after success, setContext to newly registered user and then navigate to home. Server properly responds and registers user, but when setContext is called i get the following error: "index.mjs:552 Uncaught (in promise) Error: Function called outside component initialization"
<script>
import { setContext } from 'svelte'
async function handleRegistration(e) {
let user = {
firstname: e.target.firstname.value,
lastname: e.target.lastname.value,
}
fetch('http://localhost:3001/api/auth/register', {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify(user)
})
.then(res => res.json())
.then(res => {
if(res.accessToken) {
user.accessToken = res.accessToken
user.refreshToken = res.refreshToken
setContext('userData', user)
navigate("/", { replace: true })
}
})
updateContext(user)
}
}
</script>
<form class="registration" on:submit|preventDefault="{handleRegistration}">
</form>
What am I doing wrong?