-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #282 from 0x74h51N/Staging
server action cookieConsent & lang prefix routing
- Loading branch information
Showing
53 changed files
with
352 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { notFound } from 'next/navigation'; | ||
|
||
export default function NotFoundCatchAll() { | ||
notFound(); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use server'; | ||
import { cookies } from 'next/headers'; | ||
|
||
export async function setCookiesConsent() { | ||
const cookieStore = cookies(); | ||
|
||
cookieStore.set('cookiesConsent', 'true', { | ||
path: '/', | ||
expires: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), | ||
sameSite: 'strict', | ||
secure: true, | ||
httpOnly: true, | ||
}); | ||
|
||
return { | ||
success: true, | ||
}; | ||
} | ||
|
||
export async function getCookieConsent(): Promise<string> { | ||
const response = await cookies().get('cookiesConsent'); | ||
if (response && response.value === 'true') { | ||
return 'true'; | ||
} | ||
return 'false'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use server'; | ||
|
||
import { cookies } from 'next/headers'; | ||
import { Locales, NEXT_LOCALE, supportedLocales } from '@/i18n/settings'; | ||
|
||
export async function switchLocaleAction(value: Locales) { | ||
if (supportedLocales.includes(value)) { | ||
cookies().set(NEXT_LOCALE, value, { | ||
path: '/', | ||
maxAge: 365 * 24 * 60 * 60, | ||
httpOnly: false, | ||
sameSite: 'strict', | ||
secure: process.env.NODE_ENV === 'production', | ||
}); | ||
|
||
return { | ||
status: 'success', | ||
}; | ||
} | ||
|
||
return { | ||
status: 'error', | ||
message: 'Unsupported locale', | ||
}; | ||
} | ||
|
||
export async function getLocaleCookie(): Promise<Locales | null> { | ||
const response = cookies().get(NEXT_LOCALE); | ||
|
||
if (response && supportedLocales.includes(response.value as Locales)) { | ||
return response.value as Locales; | ||
} | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,18 @@ | ||
'use client'; | ||
import { RootState } from '@/store'; | ||
import { getCookieConsent } from '@/app/actions/setCookiesConsent'; | ||
import { Analytics } from '@vercel/analytics/react'; | ||
import { SpeedInsights } from '@vercel/speed-insights/next'; | ||
import { getCookie, hasCookie } from 'cookies-next'; | ||
import React, { useCallback, useEffect } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
const Cookies = () => { | ||
const cookiesConsent = useSelector( | ||
(state: RootState) => state.cookieConsent.cookieConsent, | ||
); | ||
const beforeSendHandler = useCallback((e: any) => { | ||
if (hasCookie('cookiesConsent') && getCookie('cookiesConsent') === 'true') { | ||
return e; | ||
} | ||
return null; | ||
}, []); | ||
|
||
useEffect(() => { | ||
beforeSendHandler(undefined); | ||
}, [beforeSendHandler]); | ||
export default async function Layout() { | ||
const cookieConsent = await getCookieConsent(); | ||
|
||
return ( | ||
<> | ||
<Analytics mode="auto" beforeSend={beforeSendHandler} /> | ||
<SpeedInsights beforeSend={beforeSendHandler} /> | ||
{cookieConsent === 'true' ? ( | ||
<> | ||
<Analytics mode="auto" /> | ||
<SpeedInsights /> | ||
</> | ||
) : null} | ||
</> | ||
); | ||
}; | ||
|
||
export default Cookies; | ||
} |
Oops, something went wrong.
e1c4286
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
my-webpage – ./
my-webpage-git-master-tahsins-projects-0ae86724.vercel.app
www.crunchypix.com
my-webpage-tahsins-projects-0ae86724.vercel.app
my-webpage-git-staging-tahsins-projects-0ae86724.vercel.app
crunchypix.vercel.app
crunchypix.com