Added unauthorized redirect
This commit is contained in:
parent
cf37fe67e6
commit
7e3c2cf24a
26
src/middleware.ts
Normal file
26
src/middleware.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
|
|
||||||
|
export function middleware(req: NextRequest) {
|
||||||
|
const url = req.nextUrl.clone();
|
||||||
|
const path = url.pathname;
|
||||||
|
|
||||||
|
if (
|
||||||
|
path.startsWith('/customer-dashboard') ||
|
||||||
|
path.startsWith('/corporate-dashboard')
|
||||||
|
) {
|
||||||
|
const token = req.cookies.get(
|
||||||
|
`${path.includes('customer') ? 'bonus' : 'corporate'}__token`,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!token) {
|
||||||
|
url.pathname = '/login';
|
||||||
|
return NextResponse.redirect(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
export const config = {
|
||||||
|
matcher: ['/customer-dashboard/:path*', '/corporate-dashboard/:path*'],
|
||||||
|
};
|
||||||
@ -1,5 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { deleteCookie } from 'cookies-next';
|
||||||
import { subMonths } from 'date-fns';
|
import { subMonths } from 'date-fns';
|
||||||
import { Building2, LogOut, Wallet } from 'lucide-react';
|
import { Building2, LogOut, Wallet } from 'lucide-react';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
@ -104,9 +105,16 @@ export function CorporateDashboard() {
|
|||||||
<div className='flex min-h-screen flex-col px-2.5'>
|
<div className='flex min-h-screen flex-col px-2.5'>
|
||||||
<main className='flex-1 py-10'>
|
<main className='flex-1 py-10'>
|
||||||
<div className='container mx-auto max-w-6xl'>
|
<div className='container mx-auto max-w-6xl'>
|
||||||
<div className='mb-4 flex flex-col gap-4 items-start sm:justify-between sm:items-center sm:mb-8 sm:flex-row'>
|
<div className='mb-4 flex flex-col items-start gap-4 sm:mb-8 sm:flex-row sm:items-center sm:justify-between'>
|
||||||
<h1 className='text-3xl font-bold'>{t('corporate.pageTitle')}</h1>
|
<h1 className='text-3xl font-bold'>{t('corporate.pageTitle')}</h1>
|
||||||
<Button variant='outline' className='gap-2'>
|
<Button
|
||||||
|
variant='outline'
|
||||||
|
className='gap-2'
|
||||||
|
onClick={() => {
|
||||||
|
deleteCookie(`corporate__token`);
|
||||||
|
window.location.reload();
|
||||||
|
}}
|
||||||
|
>
|
||||||
<LogOut className='h-4 w-4' />
|
<LogOut className='h-4 w-4' />
|
||||||
{t('corporate.logoutButton')}
|
{t('corporate.logoutButton')}
|
||||||
</Button>
|
</Button>
|
||||||
@ -114,7 +122,11 @@ export function CorporateDashboard() {
|
|||||||
|
|
||||||
<div className='mb-10 grid gap-3 md:grid-cols-3 md:gap-6'>
|
<div className='mb-10 grid gap-3 md:grid-cols-3 md:gap-6'>
|
||||||
{/* Company Card */}
|
{/* Company Card */}
|
||||||
<Card data-aos='zoom-in' data-aos-mirror="true" className='md:col-span-2'>
|
<Card
|
||||||
|
data-aos='zoom-in'
|
||||||
|
data-aos-mirror='true'
|
||||||
|
className='md:col-span-2'
|
||||||
|
>
|
||||||
<CardHeader className='pb-2'>
|
<CardHeader className='pb-2'>
|
||||||
<CardTitle className='flex items-center gap-2'>
|
<CardTitle className='flex items-center gap-2'>
|
||||||
<Building2 className='h-5 w-5 text-red-600' />
|
<Building2 className='h-5 w-5 text-red-600' />
|
||||||
@ -178,7 +190,11 @@ export function CorporateDashboard() {
|
|||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{/* Fund Card */}
|
{/* Fund Card */}
|
||||||
<Card data-aos='zoom-in' data-aos-mirror="true" className='bg-gradient-to-br from-red-600 to-red-800 text-white'>
|
<Card
|
||||||
|
data-aos='zoom-in'
|
||||||
|
data-aos-mirror='true'
|
||||||
|
className='bg-gradient-to-br from-red-600 to-red-800 text-white'
|
||||||
|
>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className='flex items-center gap-2'>
|
<CardTitle className='flex items-center gap-2'>
|
||||||
<Wallet className='h-5 w-5' />
|
<Wallet className='h-5 w-5' />
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { deleteCookie } from 'cookies-next';
|
||||||
import { ArrowUpRight, Clock, CreditCard, LogOut, User } from 'lucide-react';
|
import { ArrowUpRight, Clock, CreditCard, LogOut, User } from 'lucide-react';
|
||||||
|
|
||||||
import { useFetchMyBonusInfoQuery } from '@/entities/bonus/api/bonus.api';
|
import { useFetchMyBonusInfoQuery } from '@/entities/bonus/api/bonus.api';
|
||||||
|
|
||||||
|
import Loader from '@/shared/components/loader';
|
||||||
import { useTextController } from '@/shared/language/hooks/use-text-controller';
|
import { useTextController } from '@/shared/language/hooks/use-text-controller';
|
||||||
import { Button } from '@/shared/shadcn-ui/button';
|
import { Button } from '@/shared/shadcn-ui/button';
|
||||||
import {
|
import {
|
||||||
@ -15,7 +17,6 @@ import {
|
|||||||
} from '@/shared/shadcn-ui/card';
|
} from '@/shared/shadcn-ui/card';
|
||||||
|
|
||||||
import { TransactionsTable } from '@/widgets/transactions-table';
|
import { TransactionsTable } from '@/widgets/transactions-table';
|
||||||
import Loader from '@/shared/components/loader';
|
|
||||||
|
|
||||||
export function CustomerDashboard() {
|
export function CustomerDashboard() {
|
||||||
const { t } = useTextController();
|
const { t } = useTextController();
|
||||||
@ -28,16 +29,27 @@ export function CustomerDashboard() {
|
|||||||
<div className='container mx-auto max-w-6xl'>
|
<div className='container mx-auto max-w-6xl'>
|
||||||
<div className='mb-8 flex items-center justify-between'>
|
<div className='mb-8 flex items-center justify-between'>
|
||||||
<h1 className='text-3xl font-bold'>{t('customer.pageTitle')}</h1>
|
<h1 className='text-3xl font-bold'>{t('customer.pageTitle')}</h1>
|
||||||
<Button variant='outline' className='gap-2'>
|
<Button
|
||||||
|
variant='outline'
|
||||||
|
className='gap-2'
|
||||||
|
onClick={() => {
|
||||||
|
deleteCookie(`bonus__token`);
|
||||||
|
window.location.reload();
|
||||||
|
}}
|
||||||
|
>
|
||||||
<LogOut className='h-4 w-4' />
|
<LogOut className='h-4 w-4' />
|
||||||
{t('customer.logoutButton')}
|
{t('customer.logoutButton')}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='mb-10 grid gap-3 md:grid-cols-3 md:gap-6'>
|
<div className='mb-10 grid gap-3 md:grid-cols-3 md:gap-6'>
|
||||||
<Card data-aos="zoom-in" data-aos-mirror="true" className='bg-gradient-to-br from-red-600 to-red-800 text-white'>
|
<Card
|
||||||
|
data-aos='zoom-in'
|
||||||
|
data-aos-mirror='true'
|
||||||
|
className='bg-gradient-to-br from-red-600 to-red-800 text-white'
|
||||||
|
>
|
||||||
{!data || isLoading ? (
|
{!data || isLoading ? (
|
||||||
<Loader/>
|
<Loader />
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
@ -73,7 +85,11 @@ export function CustomerDashboard() {
|
|||||||
|
|
||||||
{/* Bonus Card */}
|
{/* Bonus Card */}
|
||||||
{/* Customer Card */}
|
{/* Customer Card */}
|
||||||
<Card data-aos="zoom-in" data-aos-mirror="true" className='md:col-span-2'>
|
<Card
|
||||||
|
data-aos='zoom-in'
|
||||||
|
data-aos-mirror='true'
|
||||||
|
className='md:col-span-2'
|
||||||
|
>
|
||||||
<CardHeader className='pb-2'>
|
<CardHeader className='pb-2'>
|
||||||
<CardTitle className='flex items-center gap-2'>
|
<CardTitle className='flex items-center gap-2'>
|
||||||
<User className='h-5 w-5 text-red-600' />
|
<User className='h-5 w-5 text-red-600' />
|
||||||
@ -82,7 +98,7 @@ export function CustomerDashboard() {
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
{!data || isLoading ? (
|
{!data || isLoading ? (
|
||||||
<Loader/>
|
<Loader />
|
||||||
) : (
|
) : (
|
||||||
<div className='grid gap-6 md:grid-cols-2'>
|
<div className='grid gap-6 md:grid-cols-2'>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user