mirror of
https://github.com/Ategon/Jamjar.git
synced 2025-02-12 06:16:21 +00:00
Fix prod ternaries
This commit is contained in:
parent
ad7311247b
commit
3a2d5b1cb3
4 changed files with 101 additions and 6 deletions
|
@ -21,7 +21,7 @@ export default function UserPage() {
|
|||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
const response = await fetch(
|
||||
process.env.MODE === "PROD"
|
||||
process.env.NEXT_PUBLIC_MODE === "PROD"
|
||||
? "https://d2jam.com/api/v1/login"
|
||||
: "http://localhost:3005/api/v1/login",
|
||||
{
|
||||
|
|
95
src/app/signup/page.tsx
Normal file
95
src/app/signup/page.tsx
Normal file
|
@ -0,0 +1,95 @@
|
|||
"use client";
|
||||
|
||||
import { Button, Form, Input } from "@nextui-org/react";
|
||||
import { redirect } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
export default function UserPage() {
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [password2, setPassword2] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
|
||||
return (
|
||||
<div className="absolute flex items-center justify-center top-0 left-0 w-screen h-screen">
|
||||
<Form
|
||||
className="w-full max-w-xs flex flex-col gap-4"
|
||||
validationBehavior="native"
|
||||
onReset={() => {
|
||||
setUsername("");
|
||||
setPassword("");
|
||||
}}
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
const response = await fetch(
|
||||
process.env.NEXT_PUBLIC_MODE === "PROD"
|
||||
? "https://d2jam.com/api/v1/login"
|
||||
: "http://localhost:3005/api/v1/login",
|
||||
{
|
||||
body: JSON.stringify({ username: username, password: password }),
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
}
|
||||
);
|
||||
|
||||
if (response.status == 401) {
|
||||
setError("Invalid username or password");
|
||||
setPassword("");
|
||||
return;
|
||||
}
|
||||
|
||||
const token = await response.json();
|
||||
document.cookie = `token=${token}`;
|
||||
|
||||
redirect("/");
|
||||
}}
|
||||
>
|
||||
<Input
|
||||
isRequired
|
||||
errorMessage="Please enter a valid username"
|
||||
label="Username"
|
||||
labelPlacement="outside"
|
||||
name="username"
|
||||
placeholder="Enter your username"
|
||||
type="text"
|
||||
value={username}
|
||||
onValueChange={setUsername}
|
||||
/>
|
||||
|
||||
<Input
|
||||
isRequired
|
||||
errorMessage="Please enter a valid password"
|
||||
label="Password"
|
||||
labelPlacement="outside"
|
||||
name="password"
|
||||
placeholder="Enter your password"
|
||||
type="password"
|
||||
value={password}
|
||||
onValueChange={setPassword}
|
||||
/>
|
||||
<Input
|
||||
isRequired
|
||||
errorMessage="Please enter a valid password"
|
||||
label="Password"
|
||||
labelPlacement="outside"
|
||||
name="password"
|
||||
placeholder="Enter your password"
|
||||
type="password"
|
||||
value={password}
|
||||
onValueChange={setPassword}
|
||||
/>
|
||||
<div className="flex gap-2">
|
||||
<Button color="primary" type="submit">
|
||||
Submit
|
||||
</Button>
|
||||
<Button type="reset" variant="flat">
|
||||
Reset
|
||||
</Button>
|
||||
</div>
|
||||
<p>Sign up is being worked on currently</p>
|
||||
{error && <p className="text-red-500">{error}</p>}
|
||||
{}
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
}
|
|
@ -19,7 +19,7 @@ import {
|
|||
Tooltip,
|
||||
} from "@nextui-org/react";
|
||||
import { SiDiscord, SiForgejo, SiGithub } from "@icons-pack/react-simple-icons";
|
||||
import { LogInIcon } from "lucide-react";
|
||||
import { LogInIcon, NotebookPen } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { hasCookie, getCookies } from "@/helpers/cookie";
|
||||
import { usePathname } from "next/navigation";
|
||||
|
@ -37,7 +37,7 @@ export default function Navbar() {
|
|||
}
|
||||
|
||||
const response = await fetch(
|
||||
process.env.MODE === "PROD"
|
||||
process.env.NEXT_PUBLIC_MODE === "PROD"
|
||||
? "https://d2jam.com/api/v1/self"
|
||||
: "http://localhost:3005/api/v1/self",
|
||||
{
|
||||
|
@ -139,7 +139,7 @@ export default function Navbar() {
|
|||
</Button>
|
||||
</Link>
|
||||
</NavbarItem>
|
||||
{/* <NavbarItem>
|
||||
<NavbarItem>
|
||||
<Link href="/signup">
|
||||
<Button
|
||||
endContent={<NotebookPen />}
|
||||
|
@ -149,7 +149,7 @@ export default function Navbar() {
|
|||
Sign up
|
||||
</Button>
|
||||
</Link>
|
||||
</NavbarItem> */}
|
||||
</NavbarItem>
|
||||
</div>
|
||||
) : (
|
||||
<Dropdown>
|
||||
|
|
|
@ -10,7 +10,7 @@ export default function Posts() {
|
|||
useEffect(() => {
|
||||
const fetchPosts = async () => {
|
||||
const response = await fetch(
|
||||
process.env.MODE === "PROD"
|
||||
process.env.NEXT_PUBLIC_MODE === "PROD"
|
||||
? "https://d2jam.com/api/v1/posts"
|
||||
: "http://localhost:3005/api/v1/posts"
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue