Skip to content

Commit

Permalink
Revert "[Router][TS] Auto-complete route names for unauthenticated pr…
Browse files Browse the repository at this point in the history
…op (#11756)" (#11905)
  • Loading branch information
Tobbe authored Jan 17, 2025
1 parent 4ee5661 commit a39e340
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
8 changes: 0 additions & 8 deletions .changesets/11756.md

This file was deleted.

35 changes: 21 additions & 14 deletions packages/router/src/Set.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import type { ReactElement, ReactNode } from 'react'
import React from 'react'

import type { routes } from '@redwoodjs/router'
export type WrapperType<WTProps> = (
props: Omit<WTProps, 'wrap' | 'children'> & {
children: ReactNode
},
) => ReactElement | null

type SetProps<P> = (P extends React.FC ? React.ComponentProps<P> : unknown) & {
type SetProps<P> = P & {
/**
* A react component that the children of the Set will be wrapped
* in (typically a Layout component)
* P is the interface for the props that are forwarded to the wrapper
* components. TypeScript will most likely infer this for you, but if you
* need to you can specify it yourself in your JSX like so:
* <Set<{theme: string}> wrap={ThemableLayout} theme="dark">
*/
wrap?: P | P[]
wrap?: WrapperType<P> | WrapperType<P>[]
/**
*`Routes` nested in a `<Set>` with `private` specified require
* authentication. When a user is not authenticated and attempts to visit
Expand All @@ -22,7 +28,7 @@ type SetProps<P> = (P extends React.FC ? React.ComponentProps<P> : unknown) & {
*
* @deprecated Please use `<PrivateSet>` instead and specify this prop there
*/
unauthenticated?: keyof typeof routes
unauthenticated?: string
/**
* Route is permitted when authenticated and user has any of the provided
* roles such as "admin" or ["admin", "editor"]
Expand All @@ -37,18 +43,22 @@ type SetProps<P> = (P extends React.FC ? React.ComponentProps<P> : unknown) & {
}

/**
* A set containing public `<Route />`s
* TypeScript will often infer the type of the props you can forward to the
* wrappers for you, but if you need to you can specify it yourself in your
* JSX like so:
* <Set<{theme: string}> wrap={ThemeableLayout} theme="dark">
*/
export function Set<WrapperProps>(props: SetProps<WrapperProps>) {
// @MARK: Virtual Component, this is actually never rendered
// See analyzeRoutes in utils.tsx, inside the isSetNode block
return <>{props.children}</>
}

type PrivateSetProps<P> = Omit<SetProps<P>, 'private' | 'unauthenticated'> & {
/** The page name where a user will be redirected when not authenticated */
unauthenticated: keyof typeof routes
}
type PrivateSetProps<P> = P &
Omit<SetProps<P>, 'private' | 'unauthenticated'> & {
/** The page name where a user will be redirected when not authenticated */
unauthenticated: string
}

/** @deprecated Please use `<PrivateSet>` instead */
export function Private<WrapperProps>(props: PrivateSetProps<WrapperProps>) {
Expand All @@ -57,9 +67,6 @@ export function Private<WrapperProps>(props: PrivateSetProps<WrapperProps>) {
return <>{props.children}</>
}

/**
* A set containing private `<Route />`s that require authentication to access
*/
export function PrivateSet<WrapperProps>(props: PrivateSetProps<WrapperProps>) {
// @MARK Virtual Component, this is actually never rendered
// See analyzeRoutes in utils.tsx, inside the isSetNode block
Expand Down

0 comments on commit a39e340

Please sign in to comment.