Skip to content

Commit

Permalink
feat: add sign up api call
Browse files Browse the repository at this point in the history
  • Loading branch information
Slartibartfass2 committed Dec 12, 2024
1 parent 530701b commit 88b7e15
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
12 changes: 10 additions & 2 deletions src/lib/controller/backend-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,17 @@ export class BackendController implements IBackendController {
throw new Error("Method not implemented.");
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async createUser(personalInfo: UserSpec, password: string): Promise<User> {
throw new Error("Method not implemented.");
const payload = {
email: personalInfo.email,
sender: {
firstName: personalInfo.firstName,
lastName: personalInfo.lastName,
password: password,
},
};

return this.client.post("users", payload).then((response) => response.json());
}

user(userId: number): IUserController {
Expand Down
26 changes: 15 additions & 11 deletions src/routes/(auth)/signup/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,37 @@
import PasswordInput from "$lib/components/composites/input/PasswordInput.svelte";
import { Button } from "$lib/components/primitives/button/index.js";
import * as Card from "$lib/components/primitives/card/index.js";
import { BackendController } from "$lib/controller/backend-controller";
import type { UserSpec } from "$lib/model/backend";
import { Schema } from "$lib/schemas";
let firstNameInput: Input;
let lastNameInput: Input;
let emailInput: Input;
let passwordInput: PasswordInput;
function handleSubmit(event: Event) {
async function handleSubmit(event: Event) {
event.preventDefault();
const areInputsValid =
firstNameInput.validate() &&
lastNameInput.validate() &&
emailInput.validate() &&
passwordInput.validate();
if (!areInputsValid) {
const isFirstNameValid = firstNameInput.validate();
const isLastNameValid = lastNameInput.validate();
const isEmailValid = emailInput.validate();
const isPasswordValid = passwordInput.validate();
if (!(isFirstNameValid && isLastNameValid && isEmailValid && isPasswordValid)) {
return;
}
const signUpData = {
const userSpec: UserSpec = {
firstName: firstNameInput.getValue(),
lastName: lastNameInput.getValue(),
email: emailInput.getValue(),
password: passwordInput.getValue(),
};
// TODO: CALL API TO SIGN UP
console.log("sign up with", signUpData);
const user = await BackendController.getInstance().createUser(
userSpec,
passwordInput.getValue(),
);
// TODO: Login and redirect to the home page
console.log(user);
}
</script>

Expand Down

0 comments on commit 88b7e15

Please sign in to comment.