Register working

This commit is contained in:
sprechtl 2022-10-03 23:16:57 +02:00
parent 05735972ae
commit fea54cc943
2 changed files with 33 additions and 1 deletions

View file

@ -45,8 +45,8 @@
maxAge: 30 * 24 * 60 * 60, maxAge: 30 * 24 * 60 * 60,
path: '/' path: '/'
}) })
window.location = "/";
} }
window.location = "/";
} }
} }

View file

@ -1,6 +1,8 @@
<script lang="ts"> <script lang="ts">
import logo from "../../resources/images/logo2.svg"; import logo from "../../resources/images/logo2.svg";
import {SvelteToast} from "@zerodevx/svelte-toast"; import {SvelteToast} from "@zerodevx/svelte-toast";
import type {Authentication} from "../login/models/authentication";
import {createErrorToast} from "../../models/customToasts";
let user: string; let user: string;
let password: string; let password: string;
@ -11,6 +13,36 @@
* Handles the button click. * Handles the button click.
*/ */
async function handleSubmit() { async function handleSubmit() {
console.log("TEST")
const endpoint = "http://localhost:1337/api/auth/local/register";
const payload = {
email: email,
password: password,
username: user
};
const login = await fetch(endpoint, {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
})
const response: Authentication = await login.json();
if (response.error != null) {
if (response.error.details.errors) {
for (const error of response.error.details.errors) {
createErrorToast(error.message);
}
} else {
createErrorToast(response.error.message);
}
} else {
window.location = "/login";
}
} }
</script> </script>