Skip to content

Commit

Permalink
[DPCP-71]: CSRF Fix (#30)
Browse files Browse the repository at this point in the history
* ar(fix) pro cache

* ar(fix) [DPCP-71]: CSRF Fix

* ar(fix) [DPCP-71]: CSRF Fix

* ar(fix) [DPCP-71]: CSRF Fix

---------

Signed-off-by: Angelo Reale <[email protected]>
  • Loading branch information
angeloreale authored Aug 7, 2024
1 parent d7b2b9b commit a91bbaa
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ License: HPL3-ECO-AND-ANC 2021—Present
Purizu di Angelo Reale Caldeira de Lemos dba DreamPip

IT02925300903

1 change: 1 addition & 0 deletions lib/auth/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const methods = {
Cookie: params?.cookies,
},
credentials: 'include',
cache: 'no-store',
});
const session = await response?.json();
return session;
Expand Down
9 changes: 7 additions & 2 deletions src/app/components/client/elements/signup-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useContext, useEffect, useRef, useState } from 'react';
import { signIn, signOut, getCsrf } from "@auth";
import { AuthContext } from '@state';
import { ALogIn, ALogOut } from '@actions';
import { navigate } from '@gateway';
import { navigate, setCookie } from '@gateway';
import { Button, TextInput, Logo, Typography } from "@dreampipcom/oneiros";

interface IAuthProvider {
Expand Down Expand Up @@ -54,7 +54,12 @@ export const VSignUp = ({ providers, user }: VSignUpProps) => {
const coercedName = name || user?.name || user?.email || "Young Padawan";

useEffect(() => {
if(!csrf) getCsrf().then((_csrf) => setCsrf(_csrf));
if(!csrf) {
getCsrf().then((_csrf) => {
setCsrf(_csrf);
setCookie({ name: '__Host-authjs.csrf-token', value: _csrf });
});
}
}, [csrf]);

useEffect(() => {
Expand Down
6 changes: 6 additions & 0 deletions src/app/gateway/client/actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// actions.ts
'use server';
import { redirect } from 'next/navigation';
import { cookies } from 'next/headers';

export async function navigate(url: string) {
redirect(url);
}

export async function setCookie({ name, value }: { name: string; value: string }) {
// Set cookie
cookies().set(name, value);
}
2 changes: 1 addition & 1 deletion src/app/gateway/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// index.ts

// client
export { navigate } from './client/actions';
export { navigate, setCookie } from './client/actions';

// server
export { getUser, loadChars, reloadChars, getChars } from './server/actions';
Expand Down

0 comments on commit a91bbaa

Please sign in to comment.