initial commit

This commit is contained in:
ferdiansyah783
2025-08-05 12:35:40 +07:00
commit fffa2ead5c
1069 changed files with 118056 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
'use client'
// Type Imports
import type { Locale } from '@configs/i18n'
import type { ChildrenType } from '@core/types'
import { useEffect } from 'react'
import { useAuth } from '../contexts/authContext'
// Component Imports
import { redirect } from 'next/navigation'
import Loading from '../components/layout/shared/Loading'
import { getLocalizedUrl } from '../utils/i18n'
export default function AuthGuard({ children, locale }: ChildrenType & { locale: Locale }) {
const { isAuthenticated } = useAuth()
console.log('isAuthenticated', isAuthenticated)
useEffect(() => {
if (!isAuthenticated) {
redirect(getLocalizedUrl('/login', locale))
}
}, [isAuthenticated])
return <>{isAuthenticated ? children : <Loading />}</>
}
+23
View File
@@ -0,0 +1,23 @@
// Next Imports
// Type Imports
import type { Locale } from '@configs/i18n'
import type { ChildrenType } from '@core/types'
// Config Imports
// Util Imports
const GuestOnlyRoute = async ({ children, lang }: ChildrenType & { lang: Locale }) => {
// const session = await getServerSession()
// if (session) {
// redirect(getLocalizedUrl(themeConfig.homePageUrl, lang))
// }
console.log(lang)
return <>{children}</>
}
export default GuestOnlyRoute
+28
View File
@@ -0,0 +1,28 @@
// Next Imports
import type { headers } from 'next/headers'
// Type Imports
import type { Locale } from '@configs/i18n'
import type { ChildrenType } from '@core/types'
// Component Imports
import LangRedirect from '@components/LangRedirect'
// Config Imports
import { i18n } from '@configs/i18n'
// ️ We've to create this array because next.js makes request with `_next` prefix for static/asset files
const invalidLangs = ['_next']
const TranslationWrapper = (
props: { headersList: Awaited<ReturnType<typeof headers>>; lang: Locale } & ChildrenType
) => {
const doesLangExist = i18n.locales.includes(props.lang)
// ️ This doesn't mean MISSING, it means INVALID
const isInvalidLang = invalidLangs.includes(props.lang)
return doesLangExist || isInvalidLang ? props.children : <LangRedirect />
}
export default TranslationWrapper