Skip to content
This repository was archived by the owner on Jul 5, 2025. It is now read-only.

Commit f33b675

Browse files
committed
feat: implement sign up page
1 parent 7f719f0 commit f33b675

File tree

14 files changed

+342
-38
lines changed

14 files changed

+342
-38
lines changed

src/app/(utils)/getFormBoolean.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const getFormBoolean = (
2+
formData: FormData,
3+
fieldName: string,
4+
): boolean => formData.get(fieldName)?.toString() === "on";

src/app/Navbar.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,14 @@ export const Navbar = async () => {
7777
/>
7878
</StyledLink>
7979
) : (
80-
<StyledLink className={"text-neutral-200"} href={"/login"}>
81-
{"Log in"}
82-
</StyledLink>
80+
<>
81+
<StyledLink className={"mx-2 text-neutral-200"} href={"/login"}>
82+
{"Log in"}
83+
</StyledLink>
84+
<StyledLink className={"text-neutral-200"} href={"/signup"}>
85+
{"Sign up"}
86+
</StyledLink>
87+
</>
8388
)}
8489
</span>
8590
</nav>

src/app/apiClient.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ const fetchWithNextConfig = async (
1616
): Promise<Response> => {
1717
const additionalHeaders: Record<string, string> = {};
1818
const jwt = await getJwtFromAuthCookie();
19+
let isAuthenticatedUser = false;
1920

2021
if (jwt) {
2122
additionalHeaders["authorization"] = `Bearer ${jwt}`;
23+
isAuthenticatedUser = true;
2224
}
2325

2426
const incomingHeaders = headers();
@@ -33,15 +35,27 @@ const fetchWithNextConfig = async (
3335
additionalHeaders["x-real-ip"] = realIp;
3436
}
3537

38+
// Cache API responses for 15 seconds by default
39+
let revalidate = 15;
40+
41+
// Don't cache responses for authenticated users
42+
if (isAuthenticatedUser) {
43+
revalidate = 0;
44+
}
45+
46+
// Never cache captchas
47+
if (input.toString().includes("/api/v3/user/get_captcha")) {
48+
revalidate = 0;
49+
}
50+
3651
const res = await fetch(input, {
3752
...init,
3853
headers: {
3954
...init?.headers,
4055
...additionalHeaders,
4156
},
4257
next: {
43-
// Cache API responses for 15 seconds for logged out users
44-
revalidate: jwt !== null ? 0 : 15,
58+
revalidate,
4559
},
4660
});
4761

src/app/create_post/PostEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const PostEditor = (props: {
7676
/>
7777
</div>
7878
<input
79-
autoComplete={"false"}
79+
autoComplete={"off"}
8080
className={"hidden"}
8181
id={"honey"}
8282
name={"honey"}

src/app/create_private_message/[userid]/PrivateMessageEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const PrivateMessageEditor = (props: {
3838
/>
3939
</div>
4040
<input
41-
autoComplete={"false"}
41+
autoComplete={"off"}
4242
className={"hidden"}
4343
id={"honey"}
4444
name={"honey"}

src/app/error.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const Error = ({
1010
return (
1111
<main className={"flex h-full flex-col items-center justify-center"}>
1212
<h2 className={"mt-20 text-center text-2xl"}>
13-
{"Something went wrong!"}
13+
{error.message ? `Error: ${error.message}` : "Something went wrong!"}
1414
</h2>
1515
<div>
1616
{
@@ -31,8 +31,8 @@ export const Error = ({
3131
</>
3232
)}
3333
<button
34-
className={`bg-primary-500 hover:bg-primary-400 mt-4 rounded-md px-4 py-2 text-sm text-white
35-
transition-colors`}
34+
className={`mt-4 rounded-md bg-primary-500 px-4 py-2 text-sm text-white transition-colors
35+
hover:bg-primary-400`}
3636
onClick={() => reset()}
3737
>
3838
{"Try again"}

src/app/login/authActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const loginAction = async (
2929
throw new Error("Authentication failed");
3030
}
3131

32-
setAuthCookie(loginResponse.jwt);
32+
await setAuthCookie(loginResponse.jwt);
3333

3434
redirect(redirectUrl ?? "/");
3535
};
@@ -60,7 +60,7 @@ export const isLoggedIn = async (): Promise<boolean> => {
6060

6161
const oneMonthMillis = 30 * 24 * 60 * 60 * 1000;
6262

63-
const setAuthCookie = (token: string) => {
63+
export const setAuthCookie = async (token: string) => {
6464
cookies().set({
6565
name: AUTH_COOKIE_NAME,
6666
value: token,

src/app/login/page.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const LoginPage = async (props: {
1010
return (
1111
<div
1212
className={
13-
"flex min-h-full flex-1 flex-col items-center justify-center px-4 py-12 lg:px-8"
13+
"mt-8 flex flex-1 flex-col items-center justify-center px-4 lg:px-8"
1414
}
1515
>
1616
{siteView.site.banner && (
@@ -35,10 +35,7 @@ const LoginPage = async (props: {
3535

3636
<p className={"mt-10 text-center text-sm"}>
3737
{"No account?"}{" "}
38-
<StyledLink
39-
className={"hover:text-primary-400 font-semibold leading-6"}
40-
href={"/signup"}
41-
>
38+
<StyledLink className={"font-semibold leading-6"} href={"/signup"}>
4239
{"Sign up here"}
4340
</StyledLink>
4441
</p>

src/app/login_reset/sent/page.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import { Input } from "@/app/(ui)/form/Input";
2-
import { SubmitButton } from "@/app/(ui)/button/SubmitButton";
3-
4-
const ForgotPasswordPage = () => {
1+
const ResetLinkSentPage = () => {
52
return (
63
<div className={"m-2 lg:mx-4"}>
7-
<h1 className={"text-xl font-bold"}>{"Forgot password"}</h1>
8-
<div className={"mt-10 max-w-[600px] text-neutral-300"}>
4+
<h1 className={"mb-2 text-xl font-bold"}>{"Forgot password"}</h1>
5+
<div className={"max-w-[600px] text-neutral-300"}>
96
{"A password reset link has been sent to your e-mail."}
107
</div>
118
</div>
129
);
1310
};
1411

15-
export default ForgotPasswordPage;
12+
export default ResetLinkSentPage;

src/app/settings/loggedInUserActions.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
SortType,
1010
} from "lemmy-js-client";
1111
import { revalidatePath } from "next/cache";
12+
import { getFormBoolean } from "@/app/(utils)/getFormBoolean";
1213

1314
export type UnreadCounts = {
1415
inbox: GetUnreadCountResponse;
@@ -47,20 +48,18 @@ export const updateSettingsAction = async (formData: FormData) => {
4748
| ListingType
4849
| undefined,
4950
default_sort_type: formData.get("sort")?.toString() as SortType | undefined,
50-
show_nsfw: getFormBoolean(formData.get("nsfw_show")),
51-
blur_nsfw: getFormBoolean(formData.get("nsfw_blur")),
52-
auto_expand: getFormBoolean(formData.get("auto_expand")),
53-
show_scores: getFormBoolean(formData.get("show_scores")),
54-
bot_account: getFormBoolean(formData.get("is_bot")),
55-
show_bot_accounts: getFormBoolean(formData.get("show_bots")),
56-
show_read_posts: getFormBoolean(formData.get("show_read_posts")),
51+
show_nsfw: getFormBoolean(formData, "nsfw_show"),
52+
blur_nsfw: getFormBoolean(formData, "nsfw_blur"),
53+
auto_expand: getFormBoolean(formData, "auto_expand"),
54+
show_scores: getFormBoolean(formData, "show_scores"),
55+
bot_account: getFormBoolean(formData, "is_bot"),
56+
show_bot_accounts: getFormBoolean(formData, "show_bots"),
57+
show_read_posts: getFormBoolean(formData, "show_read_posts"),
5758
send_notifications_to_email: getFormBoolean(
58-
formData.get("notification_emails"),
59+
formData,
60+
"notification_emails",
5961
),
6062
});
6163
revalidatePath("/settings");
6264
revalidatePath("/");
6365
};
64-
65-
const getFormBoolean = (value: FormDataEntryValue | null): boolean =>
66-
value?.toString() === "on";

0 commit comments

Comments
 (0)