mirror of
https://github.com/usatiuk/y.git
synced 2025-10-28 10:37:47 +01:00
little login fixum
This commit is contained in:
@@ -13,6 +13,7 @@ import { Home } from "./Home";
|
||||
import { loginAction, signupAction } from "./actions";
|
||||
import { homeLoader } from "./loaders";
|
||||
import { isError } from "./api/dto";
|
||||
import { Feed } from "./Feed";
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
@@ -39,6 +40,7 @@ const router = createBrowserRouter([
|
||||
return ret;
|
||||
},
|
||||
element: <Home />,
|
||||
children: [{ path: "feed", element: <Feed /> }],
|
||||
},
|
||||
{
|
||||
path: "/login",
|
||||
|
||||
3
client/src/Feed.tsx
Normal file
3
client/src/Feed.tsx
Normal file
@@ -0,0 +1,3 @@
|
||||
export function Feed() {
|
||||
return <a>feed</a>;
|
||||
}
|
||||
@@ -9,7 +9,7 @@ export function Login() {
|
||||
| undefined;
|
||||
|
||||
if (data && !isError(data)) {
|
||||
return <div className="authForm">Success, now log in!;</div>;
|
||||
return <div className="authForm">Login success</div>;
|
||||
}
|
||||
|
||||
let errors: JSX.Element[] = [];
|
||||
|
||||
@@ -9,7 +9,7 @@ export function Signup() {
|
||||
| undefined;
|
||||
|
||||
if (data && !isError(data)) {
|
||||
return <div className="authForm">Success, now log in!;</div>;
|
||||
return <div className="authForm">Signup success</div>;
|
||||
}
|
||||
|
||||
let errors: JSX.Element[] = [];
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function loginAction({ request }: ActionFunctionArgs) {
|
||||
formData.get("password")!.toString(),
|
||||
);
|
||||
|
||||
if (!isError(ret)) {
|
||||
if (ret && !isError(ret)) {
|
||||
setToken(ret.token);
|
||||
return redirect("/home");
|
||||
}
|
||||
@@ -21,9 +21,26 @@ export async function loginAction({ request }: ActionFunctionArgs) {
|
||||
|
||||
export async function signupAction({ request }: ActionFunctionArgs) {
|
||||
const formData = await request.formData();
|
||||
return await signup(
|
||||
const s = await signup(
|
||||
formData.get("username")!.toString(),
|
||||
formData.get("fullName")!.toString(),
|
||||
formData.get("password")!.toString(),
|
||||
);
|
||||
|
||||
if (!s || isError(s)) {
|
||||
return s;
|
||||
}
|
||||
|
||||
// Login if everything's OK
|
||||
const ret = await login(
|
||||
formData.get("username")!.toString(),
|
||||
formData.get("password")!.toString(),
|
||||
);
|
||||
|
||||
if (ret && !isError(ret)) {
|
||||
setToken(ret.token);
|
||||
return redirect("/home");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user