mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
stringify user data before commiting to local storage
This commit is contained in:
@@ -2,7 +2,7 @@ import { type ChangeEvent, useState } from "react";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { capitalise, cn, getAuthHeaders } from "@/lib/utils";
|
import { capitalise, cn } from "@/lib/utils";
|
||||||
|
|
||||||
function Field({
|
function Field({
|
||||||
label = "label",
|
label = "label",
|
||||||
@@ -63,7 +63,7 @@ export default function LogInForm() {
|
|||||||
|
|
||||||
fetch(`${serverURL}/auth/login`, {
|
fetch(`${serverURL}/auth/login`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json", ...getAuthHeaders() },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
|
||||||
body: JSON.stringify({ username, password }),
|
body: JSON.stringify({ username, password }),
|
||||||
})
|
})
|
||||||
@@ -72,7 +72,7 @@ export default function LogInForm() {
|
|||||||
setError("");
|
setError("");
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
localStorage.setItem("token", data.token);
|
localStorage.setItem("token", data.token);
|
||||||
localStorage.setItem("user", data.user);
|
localStorage.setItem("user", JSON.stringify(data.user));
|
||||||
window.location.href = "";
|
window.location.href = "";
|
||||||
}
|
}
|
||||||
// unauthorized
|
// unauthorized
|
||||||
@@ -104,7 +104,7 @@ export default function LogInForm() {
|
|||||||
|
|
||||||
fetch(`${serverURL}/auth/register`, {
|
fetch(`${serverURL}/auth/register`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name,
|
name,
|
||||||
username,
|
username,
|
||||||
@@ -116,7 +116,7 @@ export default function LogInForm() {
|
|||||||
setError("");
|
setError("");
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
localStorage.setItem("token", data.token);
|
localStorage.setItem("token", data.token);
|
||||||
localStorage.setItem("user", data.user);
|
localStorage.setItem("user", JSON.stringify(data.user));
|
||||||
window.location.href = "";
|
window.location.href = "";
|
||||||
}
|
}
|
||||||
// bad request (probably a bad user input)
|
// bad request (probably a bad user input)
|
||||||
|
|||||||
Reference in New Issue
Block a user