Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Can we redirect to non /admin route after login?

default discord avatar
superwafflepuffslast year
1

I have a custom route in express that uses paylaod auth and if the user is logged out it sends them to the

http://localhost:3000/admin/login?redirect=%sFutils%2Fadd-device%2F1234

However after login they are redirected to

http://localhost:3000/admin/utils/add-device/1234

Is there a way to allow me to redirect to the correct route?



Resolved by switching to a custom view:

https://payloadcms.com/docs/admin/components#views
  • default discord avatar
    matthew_cook_genslerlast year

    Could you share the view you used as an example? I'm working on a similar issue.



    My example, which overrides the admin homepage:


    payload.config.ts
    admin: {
     views: {
            LoginRedirect: {
              Component: LoginRedirect,
              path: '/',
              exact: true
            }
          }
    }

    LoginRedirect.tsx
    import React from 'react';
    import { AdminViewComponent } from 'payload/config'
    
    export const LoginRedirect: AdminViewComponent = (props) => {
    
      const { user } = props
    
      switch (user.role) {
        case "admin": {
          window.location.href = '../admin/collections/sessions'
          break;
        }
        // ... other cases for all roles
    }
    
      return <></>
    }
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.