feat: restructure routing and layouts for admin and news sections, update cookie paths
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { redirect } from 'react-router'
|
||||
import { NewsPage } from '~/pages/news'
|
||||
|
||||
export async function loader() {
|
||||
return redirect('/news')
|
||||
const NewsIndexLayout = () => {
|
||||
return <NewsPage />
|
||||
}
|
||||
|
||||
export default NewsIndexLayout
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
import { NewsPage } from '~/pages/news'
|
||||
|
||||
const NewsIndexLayout = () => {
|
||||
return <NewsPage />
|
||||
}
|
||||
|
||||
export default NewsIndexLayout
|
||||
@@ -4,7 +4,7 @@ import { NewsProvider } from '~/contexts/news'
|
||||
import { NewsDefaultLayout } from '~/layouts/news/default'
|
||||
import { handleCookie } from '~/libs/cookies'
|
||||
|
||||
import type { Route } from './+types/_layout.news'
|
||||
import type { Route } from './+types/_layout'
|
||||
|
||||
export const loader = async ({ request }: Route.LoaderArgs) => {
|
||||
const { userToken } = await handleCookie(request)
|
||||
@@ -7,7 +7,7 @@ import { newsLoginRequest } from '~/apis/news/login'
|
||||
import { loginSchema, type TLoginSchema } from '~/layouts/news/form-login'
|
||||
import { generateTokenCookie } from '~/utils/token'
|
||||
|
||||
import type { Route } from './+types/actions.news.login'
|
||||
import type { Route } from './+types/actions.login'
|
||||
|
||||
export const action = async ({ request }: Route.ActionArgs) => {
|
||||
try {
|
||||
@@ -46,14 +46,22 @@ export const action = async ({ request }: Route.ActionArgs) => {
|
||||
)
|
||||
} catch (error) {
|
||||
if (error instanceof XiorError) {
|
||||
return data({
|
||||
success: false,
|
||||
message: error?.response?.data?.error?.message || error.message,
|
||||
})
|
||||
return data(
|
||||
{
|
||||
success: false,
|
||||
message: error?.response?.data?.error?.message || error.message,
|
||||
},
|
||||
{
|
||||
status: error?.response?.status || 500,
|
||||
},
|
||||
)
|
||||
}
|
||||
return data({
|
||||
success: false,
|
||||
message: 'Internal server error',
|
||||
})
|
||||
return data(
|
||||
{
|
||||
success: false,
|
||||
message: 'Internal server error',
|
||||
},
|
||||
{ status: 500 },
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user