Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update auth config to allow authorized images (#400) #422

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dashboard/final-example/auth.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ export const authConfig = {
callbacks: {
authorized({ auth, request: { nextUrl } }) {
const isLoggedIn = !!auth?.user;
const isOnDashboard = nextUrl.pathname.startsWith('/dashboard');
if (isOnDashboard) {
const protectedPaths = ['/dashboard', '/customers', '/invoices'];
const isProtectedPath = protectedPaths.some((path) =>
nextUrl.pathname.startsWith(path),
);
Comment on lines +14 to +17
Copy link
Collaborator

@delbaoliveira delbaoliveira Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @tylerhoward15, thank you for the contribution. This was resolved in this PR: #355

Are you still seeing broken images? I'm not able to reproduce.

In either case:

  • The protected pathname starts with /dashboard. E.g. /dashboard/customers. So startsWith would evaluate to false for /customers.
  • I think it's slightly better practice to protect a route higher up (/dashboard), so that if we add or change the name of a child segment, they'd automatically be protected.


if (isProtectedPath) {
if (isLoggedIn) return true;
return false; // Redirect unauthenticated users to login page
} else if (isLoggedIn) {
Expand Down
Loading