session

ruby
class OnboardingForm
  include ActiveModel::Model
  include ActiveModel::Attributes

  STEPS = %i[account profile preferences].freeze

Multi-Step Wizard Form in Rails with a Form Object and Session-Backed State

rails form-objects activemodel
by codesnips 3 tabs
javascript
import { createContext, useContext, useEffect, useMemo, useState } from 'react';
import { fetchCurrentUser, postLogin, postLogout } from './api';

const AuthContext = createContext(null);

export function AuthProvider({ children }) {

Protecting React Routes with an Auth Context and a RequireAuth Wrapper

react react-router authentication
by codesnips 4 tabs
ruby
class WizardsController < ApplicationController
  STEPS = %w[account profile confirm].freeze

  before_action :set_step

  def show

Multi-step wizard navigation with Turbo Frames

rails hotwire turbo
by codesnips 4 tabs
typescript
import { createContext, useContext, useEffect, useMemo, useState, ReactNode } from 'react';
import { authApi, User } from './authApi';

type Status = 'loading' | 'authenticated' | 'anonymous';

interface AuthValue {

Protect React Routes with an Auth Context and a RequireAuth Wrapper

react react-router authentication
by codesnips 4 tabs
php
<?php

namespace App\Http\Requests\Wizard;

use Illuminate\Foundation\Http\FormRequest;

Multi-Step Onboarding Wizard in Laravel with Per-Step Form Requests and Session Progress

laravel forms validation
by codesnips 4 tabs
ruby
class Cart < ApplicationRecord
  belongs_to :user, optional: true
  has_many :cart_items, dependent: :destroy

  scope :for_session, ->(token) { where(session_token: token) }
  scope :active, -> { where(merged_at: nil) }

Merge a Guest Cart Into a User's Cart on Login With a Rails Service Object

rails service-object devise
by codesnips 3 tabs