Skip to content

Commit

Permalink
chore: added fix to the redirect functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
JoblersTune committed Aug 22, 2024
1 parent adbb734 commit 715fe11
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/frontend/app/lib/kratos_checks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function checkAuthAndRedirect(
const { pathname } = new URL(url)
const isAuthPath = pathname.startsWith('/auth')
const isSettingsPage = pathname.includes('/settings')
const isLogoutPage = pathname.includes('/logout')
const isLogoutPage = pathname.includes('logout')

if (!variables.authEnabled) {
// If auth is disabled users shouldn't accesses the auth path or Kratos settings pages
Expand All @@ -45,7 +45,6 @@ export async function checkAuthAndRedirect(
}
}

// auth is enabled
const loggedIn = await isLoggedIn(cookieHeader)

// Logged-in users can access all pages except auth pages, with the exception of the manual logout page
Expand All @@ -55,8 +54,8 @@ export async function checkAuthAndRedirect(
}
return
} else {
// Unauthenticated users can only access auth path pages
if (!isAuthPath) {
// Users who are not logged in can only access auth path pages and cannot logout
if (!isAuthPath || isLogoutPage) {
throw redirect('/auth')
}
return
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/app/routes/auth.manual-logout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { checkAuthAndRedirect } from '../lib/kratos_checks.server'
export const loader = async ({ request }: LoaderFunctionArgs) => {
const cookies = request.headers.get('cookie')
await checkAuthAndRedirect(request.url, cookies)
return null
}

export default function Logout() {
Expand Down

0 comments on commit 715fe11

Please sign in to comment.