diff --git a/docs/docs/tutorial/chapter4/authentication.md b/docs/docs/tutorial/chapter4/authentication.md index 6cb55d71add5..5018a194c4b1 100644 --- a/docs/docs/tutorial/chapter4/authentication.md +++ b/docs/docs/tutorial/chapter4/authentication.md @@ -829,7 +829,7 @@ export const hasRole = ({ roles }): boolean => { return false } -export const requireAuth = ({ roles }: { roles: AllowedRoles }) => { +export const requireAuth = ({ roles }: { roles?: AllowedRoles } = {}) => { if (!isAuthenticated()) { throw new AuthenticationError("You don't have permission to do that.") } diff --git a/packages/cli/src/commands/setup/auth/templates/auth.ts.template b/packages/cli/src/commands/setup/auth/templates/auth.ts.template index 237395d33527..79b2b852d971 100644 --- a/packages/cli/src/commands/setup/auth/templates/auth.ts.template +++ b/packages/cli/src/commands/setup/auth/templates/auth.ts.template @@ -110,16 +110,16 @@ export const hasRole = (roles: AllowedRoles): boolean => { * whether or not they are assigned a role, and optionally raise an * error if they're not. * - * @param roles: AllowedRoles - When checking role membership, these roles grant access. + * @param roles?: AllowedRoles - When checking role membership, these roles grant access. * * @returns - If the currentUser is authenticated (and assigned one of the given roles) * * @throws {AuthenticationError} - If the currentUser is not authenticated - * @throws {ForbiddenError} If the currentUser is not allowed due to role permissions + * @throws {ForbiddenError} - If the currentUser is not allowed due to role permissions * * @see https://github.com/redwoodjs/redwood/tree/main/packages/auth for examples */ -export const requireAuth = ({ roles }: { roles: AllowedRoles }) => { +export const requireAuth = ({ roles }: { roles?: AllowedRoles } = {}) => { if (!isAuthenticated()) { throw new AuthenticationError("You don't have permission to do that.") }