authentication

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
python
from datetime import datetime, timedelta, timezone

from jose import jwt, JWTError
from jose.exceptions import ExpiredSignatureError

SECRET_KEY = "change-me-in-production"

FastAPI JWT Authentication with Access/Refresh Tokens and a Verification Dependency

fastapi jwt authentication
by codesnips 3 tabs
java
package com.example.demo.config;

import com.example.demo.security.JwtAuthenticationFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;

Security with Spring Security and JWT

java spring-security jwt
by David Kumar 3 tabs
ruby
Rails.application.routes.draw do
  namespace :api, defaults: { format: :json } do
    namespace :v1 do
      resources :articles, only: [:index, :show, :create, :update, :destroy]
      resources :sessions, only: [:create]
    end

Versioned JSON API Namespace in Rails With a Shared Base Controller

rails api versioning
by codesnips 3 tabs