Skip to content

Commit

Permalink
feat(auth): fix issue with ablity to return to protected routes after…
Browse files Browse the repository at this point in the history
… logout
  • Loading branch information
anteqkois committed May 30, 2024
1 parent e0f9523 commit 6d28856
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions apps/web/app/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ModeToggle } from '@linkerry/ui-components/client'
import ReactQueryProvider from '../../libs/reactQueryProvider'
import { ReachLimitDialog } from '../../modules/billing/components/ReachLimitDialog'
import { ReachLimitDialogProvider } from '../../modules/billing/useReachLimitDialog'
import { AuthGuard } from '../../modules/user/AuthGuard'
import { DesktopMenu } from './components/DesktopMenu'
import { LiveCharInitializer } from './components/LiveCharInitializer'
import { MobileMenu } from './components/MobileMenu'
Expand All @@ -18,6 +19,7 @@ export default function AuthLayout({ children }: AuthLayoutProps) {
<div className="">
<ReactQueryProvider>
<UserProvider>
<AuthGuard />
<ReachLimitDialogProvider>
<div className="fixed h-14 top-0 z-40 flex justify-between items-center p-1 py-2 w-full border-b border-border/80 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
<div className="flex items-center gap-1">
Expand Down
6 changes: 3 additions & 3 deletions apps/web/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AuthStatus } from '@linkerry/shared/lib/common/auth'
import { Cookies } from '@linkerry/shared/lib/constants/cookies'
import { NextRequest, NextResponse } from 'next/server'
import { AuthStatus } from '@linkerry/shared/lib/common/auth';
import { Cookies } from '@linkerry/shared/lib/constants/cookies';
import { NextRequest, NextResponse } from 'next/server';

export function middleware(req: NextRequest) {
const authStatus = req.cookies.get(Cookies.AUTH_STATUS)
Expand Down
2 changes: 1 addition & 1 deletion apps/web/modules/billing/components/PlanCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const PlanCard = ({ price, product, className, config, onSelectPlan, pric
<CardDescription>{product.shortDescription}</CardDescription>
</CardHeader>
<CardContent>
<div className="mb-4 relative w-full h-10">
<div className="mb-4 mt-2 relative w-full h-10">
{priceSlot ? (
priceSlot
) : (
Expand Down
22 changes: 22 additions & 0 deletions apps/web/modules/user/AuthGuard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use client'

import { AuthStatus } from '@linkerry/shared'
import { useRouter } from 'next/navigation'
import { HTMLAttributes, useEffect } from 'react'
import { useUser } from './useUser'

export interface AuthGuardProps extends HTMLAttributes<HTMLElement> {}

export const AuthGuard = () => {
const { authStatus } = useUser()
const { push } = useRouter()

useEffect(() => {
if (authStatus === AuthStatus.UNAUTHENTICATED) {
console.warn('User unauthenticated')
push('/login')
}
}, [])

return <></>
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ProductsService {
})
}

return items
return items.sort((a, b) => a.priority - b.priority)
}

async findOne(id: Id) {
Expand Down

0 comments on commit 6d28856

Please sign in to comment.