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

feat: redirect unauthorized tip CRUD to /tips #43

Merged
merged 3 commits into from
Jan 4, 2024

Conversation

jbranchaud
Copy link
Collaborator

@jbranchaud jbranchaud commented Dec 21, 2023

This does a server-redirect to the /tips index page if you are unauthorized the do CRUD on tips. Instead of seeing a dead-end blank page, you land back on a page with content.

With the Page Router we would typically do this sort of auth-check and redirect in getServerSideProps

export async function getServerSideProps(context) {
  const session = await getServerAuthSession()
  const ability = getAbility({user: session?.user})

  if (!ability.can('upload', 'Media')) {
    return {
      redirect: {
        destination: '/',
        permanent: false,
      },
    }
  }
 
  return {
    props: {},
  }
}

What we can now do with a redirect call in a server-side page/component function of the App Router is a nice ergonomics improvement.

land

Copy link

vercel bot commented Dec 21, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
course-builder-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 4, 2024 5:09pm
course-builder-poc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 4, 2024 5:09pm

@github-actions github-actions bot added the apps label Dec 21, 2023
@jbranchaud jbranchaud requested a review from joelhooks January 2, 2024 19:08
Comment on lines +18 to +19
type Actions = 'create' | 'read' | 'update' | 'delete' | 'manage'
type Subjects = 'Content' | 'User' | User | 'all'
Copy link
Collaborator

Choose a reason for hiding this comment

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

had "refine these" on my todo list. Probably want to go back through CASL docs since we are using older style for some stuff.

@joelhooks joelhooks merged commit 30f3470 into main Jan 4, 2024
12 checks passed
@kodiakhq kodiakhq bot deleted the jb/redirect-from-unauthorized-page branch January 4, 2024 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants