authorization

javascript
const jwt = require('jsonwebtoken');

function authenticate(req, res, next) {
  const header = req.headers.authorization || '';
  const [scheme, token] = header.split(' ');

Role-Based Access Control in Express with a requireRole Middleware Factory

express middleware rbac
by codesnips 3 tabs
php
<?php

namespace App\Events;

use App\Models\Order;
use Illuminate\Broadcasting\PrivateChannel;

Broadcasting Order Status Updates to a Private Channel with Laravel Echo

laravel broadcasting websockets
by codesnips 4 tabs
php
<?php

use App\Http\Controllers\DocumentsController;
use Illuminate\Support\Facades\Route;

Route::middleware('auth')->group(function () {

Soft Deletes with a Trash View and Restore Route in Laravel

laravel eloquent soft-deletes
by codesnips 4 tabs
php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

Serve Purchased Downloads Behind Signed Temporary URLs in Laravel

laravel eloquent signed-urls
by codesnips 4 tabs
php
<?php

namespace App\Models\Scopes;

use App\Support\TenantContext;
use Illuminate\Database\Eloquent\Builder;

Automatic Multi-Tenant Scoping in Laravel with a Global Scope and Auth Context

laravel multi-tenancy eloquent
by codesnips 4 tabs
ruby
class SnipPolicyScope
  def initialize(member, relation = Snip.all)
    @member = member
    @relation = relation
  end

Composable “Policy Scope” without a Gem

rails authorization patterns
by Sarah Chen 2 tabs
typescript
import { SetMetadata } from '@nestjs/common';

export enum Role {
  User = 'user',
  Editor = 'editor',
  Admin = 'admin',

Role-Based Access Control in NestJS with a Custom Guard and @Roles Decorator

nestjs authorization rbac
by codesnips 3 tabs
ruby
Rails.application.routes.draw do
  resources :articles do
    resources :comments, shallow: true, only: %i[index new create show edit update destroy]
  end

  root "articles#index"

Nested Comments on Articles with Shallow Routing and Scoped Lookups in Rails

rails routing controllers
by codesnips 3 tabs
typescript
import { cookies } from "next/headers";
import { jwtVerify } from "jose";

export interface Session {
  userId: string;
  role: "user" | "admin";

Next.js Route Handler with auth guard

nextjs route-handlers authentication
by codesnips 3 tabs
php
<?php

namespace App\Security\Voter;

use App\Entity\Comment;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

Enforce Comment Ownership With a Symfony Voter and Controller Authorization Check

symfony security voter
by codesnips 3 tabs
typescript
export const PERMISSIONS = {
  READ_POSTS: 'posts:read',
  WRITE_POSTS: 'posts:write',
  DELETE_POSTS: 'posts:delete',
  MANAGE_USERS: 'users:manage',
} as const;

Typed Role-Based Route Guards with Permission Middleware in Express

express authorization rbac
by codesnips 3 tabs
typescript
import { Injectable, signal, computed } from '@angular/core';

export interface CurrentUser {
  id: string;
  email: string;
  roles: string[];

Guarding a Lazy-Loaded Angular Admin Route with a Functional CanActivate Role Check

angular routing lazy-loading
by codesnips 3 tabs