Skip to content

Commit

Permalink
chore: upgrade to nextjs15
Browse files Browse the repository at this point in the history
  • Loading branch information
corp-0 committed Oct 28, 2024
1 parent ec73172 commit fbb1e56
Show file tree
Hide file tree
Showing 13 changed files with 11,867 additions and 11,500 deletions.
4 changes: 2 additions & 2 deletions app/(account)/register/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import FormContainer from "../../common/uiLibrary/Layouters/formContainer";
import TextField from "../../common/uiLibrary/forms/textField";
import AlternativeActions from "../../common/uiLibrary/forms/alternativeActions";
import ContactInformation from "../../(home)/contactInformation";
import {useFormState} from "react-dom";
import "react-dom";
import {registerAccount, RegisterResponse} from "./actions";
import {isFieldError} from "../../../lib/auth/guards";
import { useFormStatus } from "react-dom";
Expand All @@ -18,7 +18,7 @@ const RegisterPage = () => {
success: false,
error: undefined
}
const [state, formAction] = useFormState(registerAccount, initialState);
const [state, formAction] = useActionState(registerAccount, initialState);

const uniqueIdHelperText = () =>
<>
Expand Down
3 changes: 1 addition & 2 deletions app/(account)/resend-confirm-email/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import Button from "../../common/uiLibrary/Button";
import ContactInformation from "../../(home)/contactInformation";
import React from "react";
import FullPage from "../../common/uiLibrary/Layouters/fullPage";
import {useFormState} from "react-dom";
import {postResendConfirmationMail, ResendConfirmationMailRequest} from "./actions";

const ResendConfirmationMail = () => {
const initialState: ResendConfirmationMailRequest = {
success: false,
}

const [state, formAction] = useFormState(postResendConfirmationMail, initialState);
const [state, formAction] = useActionState(postResendConfirmationMail, initialState);

const resendForm = () => {
return (
Expand Down
3 changes: 1 addition & 2 deletions app/(account)/reset-password/[token]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import React from "react";
import FormContainer from "../../../common/uiLibrary/Layouters/formContainer";
import TextField from "../../../common/uiLibrary/forms/textField";
import Button from "../../../common/uiLibrary/Button";
import {useFormState} from "react-dom";
import {postPasswordReset, ResetPasswordStep2Response} from "./actions";
import {isFieldError} from "../../../../lib/auth/guards";
import FullPage from "../../../common/uiLibrary/Layouters/fullPage";
Expand All @@ -18,7 +17,7 @@ const ResetPasswordPageStep2 = () => {
error: undefined
}

const [state, formAction] = useFormState(postPasswordReset, initialState);
const [state, formAction] = useActionState(postPasswordReset, initialState);

const successMessage = () => (
<div className='flex flex-col gap-4'>
Expand Down
3 changes: 1 addition & 2 deletions app/(account)/reset-password/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import React from "react";
import FormContainer from "../../common/uiLibrary/Layouters/formContainer";
import TextField from "../../common/uiLibrary/forms/textField";
import {requestAPasswordReset, ResetPassowrdStep1} from "./actions";
import {useFormState} from "react-dom";
import ContactInformation from "../../(home)/contactInformation";

const initialState: ResetPassowrdStep1 = {
Expand All @@ -15,7 +14,7 @@ const initialState: ResetPassowrdStep1 = {
};

const ResetPasswordPage = () => {
const [state, formAction] = useFormState(requestAPasswordReset, initialState);
const [state, formAction] = useActionState(requestAPasswordReset, initialState);

const successMessage = () => (
<div className='flex flex-col gap-4'>
Expand Down
67 changes: 0 additions & 67 deletions app/(home)/HeroRandomImageClient.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions app/(home)/HomeBannerClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ const images: string[] = [

let currentIndex = 0;

const shuffleImages = () => {
for (let i = images.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[images[i], images[j]] = [images[j], images[i]];
}
};

const getNextImage = () => {
currentIndex = (currentIndex + 1) % images.length;
return images[currentIndex];
Expand All @@ -33,8 +26,6 @@ const getNextImage = () => {
const HomeBannerClient = (props: layoutChildren) => {
const {children} = props;

shuffleImages();

const [image1, setImage1] = useState<string>(getNextImage());
const [image2, setImage2] = useState<string>(getNextImage());
const [showImage1, setShowImage1] = useState<boolean>(true);
Expand Down
6 changes: 3 additions & 3 deletions app/(home)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import LatestNews from "./latestNews";
import ContactInformation from "./contactInformation";
import React from "react";
import dynamic from 'next/dynamic';
import HomeBannerClient from "./HomeBannerClient";

const mainText = "Welcome to Unitystation!";
const secondaryText = "Free and open-source remake of the cult classic Space Station 13, made in Unity Engine.";
Expand All @@ -20,17 +21,16 @@ const fetchLatestBlogPost = async (): Promise<BlogPost[]> => {

const HomePage = async () => {
const latestBlogPosts: BlogPost[] = await fetchLatestBlogPost();
const NoSsrHomebannerClient = dynamic(() => import('./HomeBannerClient'), { ssr: false });

return (
<>
<div className="flex flex-col justify-center gap-6">
<div className="flex-[1]">
<NoSsrHomebannerClient>
<HomeBannerClient>
<LandingText mainText={mainText} secondaryText={secondaryText}/>
<DownloadButtonClient/>
<LandingButtonsServer/>
</NoSsrHomebannerClient>
</HomeBannerClient>
</div>
<div className="flex-[1]">
<LatestNews posts={latestBlogPosts}/>
Expand Down
2 changes: 1 addition & 1 deletion app/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const setMetadata = (post: BlogPost) => {

const PostPage = async (query: PageParams) => {

const {slug} = query.params;
const {slug} = await query.params;
const post: BlogPost = await fetchPost(slug as string);
setMetadata(post);

Expand Down
2 changes: 1 addition & 1 deletion app/clown/clown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Clown = () => {
const [dirX, setDirX] = useState(1);
const [dirY, setDirY] = useState(1);
const [timesClicked, setTimesClicked] = useState(0);
const audioRef: RefObject<HTMLAudioElement> = React.createRef();
const audioRef: RefObject<HTMLAudioElement | null> = React.createRef();

const handleClick = () => {
audioRef.current!.play();
Expand Down
28 changes: 14 additions & 14 deletions lib/auth/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
import {LoginResponse} from "./types";
import {EncryptJWT, jwtDecrypt, jwtVerify, SignJWT} from "jose";
import {isLoginResponse, parseError} from "./guards";
import {cookies} from "next/headers";
import { cookies, type UnsafeUnwrappedCookies } from "next/headers";
import {redirect} from "next/navigation";

const secretText = `${process.env.SECRET}`;
const secretKey = Buffer.from(secretText, 'base64');

export const tryGetSessionCookie = (): { success: boolean, value?: string } => {
try {
const sessionCooke = cookies().get("session")?.value;
if (sessionCooke) {
return { success: true, value: sessionCooke };
}
} catch (e) {
return { success: false };
export const tryGetSessionCookie = async (): Promise<{ success: boolean, value?: string }> => {
const cookiesManager = await cookies();
const sessionCookie = cookiesManager.get("session")?.value;

if (sessionCookie) {
return { success: true, value: sessionCookie };
}

return { success: false };
}

export const setSessionCookie = async (payload: LoginResponse) => {
cookies().set("session", await encryptSessionData(payload), {
const cookiesManager = await cookies();
cookiesManager.set("session", await encryptSessionData(payload), {
httpOnly: true,
expires: new Date(Date.now() + 1000 * 60 * 60 * 24)
});
}

export const destroySessionCookie = () => {
cookies().set("session", "", {
export const destroySessionCookie = async () => {
const cookiesManager = await cookies();
cookiesManager.set("session", "", {
httpOnly: true,
expires: new Date(0)
});
})
}

export const encryptSessionData = async (payload: LoginResponse) => {
Expand Down Expand Up @@ -96,7 +96,7 @@ export const serverRequestLoginWithToken = async (token: string) => {
}

export const serverTrySessionLogin = async () => {
const sessionCookie = tryGetSessionCookie();
const sessionCookie = await tryGetSessionCookie();
if (sessionCookie.success) {
const payload = await decryptSessionData(sessionCookie.value!);
if (isLoginResponse(payload)) {
Expand Down
Loading

0 comments on commit fbb1e56

Please sign in to comment.