authentication

php
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Models\User;

Laravel Sanctum for API authentication

laravel sanctum authentication
by Carlos Mendez 3 tabs
typescript
import { Request, Response } from 'express';
import { authenticate } from './auth.service';

export async function login(req: Request, res: Response): Promise<void> {
  const { email, password } = req.body ?? {};

Password hashing with Argon2

security node argon2
by codesnips 3 tabs
javascript
import * as Turbo from "@hotwired/turbo";

function metaContent(name) {
  const el = document.querySelector(`meta[name="${name}"]`);
  return el ? el.getAttribute("content") : null;
}

Attach custom headers to Turbo fetch requests (stimulus-free)

rails hotwire turbo
by codesnips 3 tabs
php
<?php

namespace App\Models;

use App\Notifications\VerifyEmailNotification;
use Illuminate\Contracts\Auth\MustVerifyEmail;

Signed Email-Verification Links with Custom Laravel Notification and Signed Routes

laravel signed-urls email-verification
by codesnips 4 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
python
from datetime import timedelta

INSTALLED_APPS += ['rest_framework_simplejwt']

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [

Django REST Framework authentication with JWT

django python rest
by Priya Sharma 2 tabs
php
<?php

namespace App\Http\Requests;

use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;

Laravel Form Request Validation for Signup With Custom Rules and Error Responses

laravel validation form-request
by codesnips 3 tabs
typescript
import { initTRPC, TRPCError } from '@trpc/server';

export interface Context {
  user: { id: string; role: 'user' | 'admin' } | null;
  db: DatabaseClient;
}

tRPC router pattern for type-safe APIs

typescript trpc api
by codesnips 4 tabs
swift
import AuthenticationServices
import CryptoKit

class SignInWithAppleManager: NSObject, ObservableObject {
    @Published var isSignedIn = false
    @Published var userID: String?

Sign in with Apple authentication

swift sign-in-apple authentication
by Sofia Martinez 1 tab
ruby
class User < ApplicationRecord
  has_secure_password

  RESET_TOKEN_TTL = 30.minutes

  def self.reset_verifier

Signed Password Reset Tokens with ActiveSupport::MessageVerifier in Rails

rails authentication password-reset
by codesnips 3 tabs
ruby
class JwtService
  ACCESS_TOKEN_LIFETIME = 15.minutes
  REFRESH_TOKEN_LIFETIME = 7.days
  SECRET = Rails.application.credentials.jwt_secret

  def self.encode_access_token(user_id)

JWT authentication with refresh tokens

rails authentication jwt
by Alex Kumar 1 tab
typescript
import { Injectable, NestMiddleware, UnauthorizedException } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';
import { TenantService } from './tenant.service';

@Injectable()
export class TenantContextMiddleware implements NestMiddleware {

Bind Tenant Context Per Request in NestJS With a Custom @TenantId() Decorator

nestjs multi-tenancy decorators
by codesnips 4 tabs