Token导航 LogoToken导航TokenDH.com
前端设计敏感数据github未标认证来源可访问许可证需确认审计通过

supabase-auth-ssr-setupSupabase auth SSR 设置

Agent Skill

用于辅助安全审计、权限检查、凭据风险、认证流程和常见漏洞排查。它适合让 Agent 梳理敏感配置、检查依赖风险、分析鉴权逻辑或生成安全复核清单。使用时不能把工具输出直接当最终结论,涉及密钥、令牌、用户数据或生产系统时,应先确认最小权限、脱敏方式和操作边界。

总安装

445

周安装

18

GitHub Stars

3

下载量

140
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:supabase-auth-ssr-setup(Supabase auth SSR 设置)
来源仓库:https://github.com/hopeoverture/worldbuilding-app-skills
仓库路径:skills/supabase-auth-ssr-setup
安装命令:
npx skills add https://github.com/hopeoverture/worldbuilding-app-skills --skill supabase-auth-ssr-setup
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/hopeoverture/worldbuilding-app-skills --skill supabase-auth-ssr-setup

简介

辅助安全审计和认证流程分析,支持常见漏洞排查。

  • 适合梳理敏感配置和检查依赖风险。
  • 通过 npx 命令从指定 GitHub 仓库安装并使用该技能。
  • 涉及密钥或用户数据时需确认最小权限和操作边界。
  • supabase-auth-ssr-setup 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Supabase Auth SSR Setup

Overview

Configure Supabase Authentication for Next.js App Router with server-side rendering (SSR), secure cookie-based sessions, middleware protection, and complete authentication flows.

Installation and Configuration Steps

1. Install Dependencies

Install Supabase SSR package for Next.js:

npm install @supabase/supabase-js @supabase/ssr

2. Create Supabase Client Utilities

Create three client configurations for different contexts (browser, server, middleware):

File: lib/supabase/client.ts (Browser client)

Use the template from assets/supabase-client.ts. This client:

  • Runs only in browser context
  • Uses secure cookies for session storage
  • Automatically refreshes tokens

File: lib/supabase/server.ts (Server component client)

Use the template from assets/supabase-server.ts. This client:

  • Creates server-side Supabase client with cookie access
  • Used in Server Components and Server Actions
  • Provides read-only cookie access for security

File: lib/supabase/middleware.ts (Middleware client)

Use the template from assets/supabase-middleware.ts. This client:

  • Used in Next.js middleware for route protection
  • Can update cookies in responses
  • Refreshes sessions on route navigation

3. Configure Environment Variables

Add Supabase credentials to .env.local:

NEXT_PUBLIC_SUPABASE_URL=your-project-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key

Get these values from your Supabase project settings under API.

Security note: The anon key is safe to expose publicly. Real security comes from Row Level Security (RLS) policies in your database.

4. Create Middleware for Route Protection

Create middleware.ts in project root using the template from assets/middleware.ts. This middleware:

  • Refreshes Supabase session on every request
  • Protects routes matching specified patterns
  • Redirects unauthenticated users to login
  • Allows public routes to bypass authentication

Configure protected routes by adjusting the matcher pattern:

export const config = {
  matcher: [
    '/dashboard/:path*',
    '/settings/:path*',
    '/api/protected/:path*',
  ],
};

5. Create Authentication Utilities

Create helper functions for common auth operations using templates from assets/auth-utils.ts:

Get current user server-side:

import { getCurrentUser } from '@/lib/auth/utils';

const user = await getCurrentUser();

Require authentication:

import { requireAuth } from '@/lib/auth/utils';

const user = await requireAuth(); // Throws error if not authenticated

Get session:

import { getSession } from '@/lib/auth/utils';

const session = await getSession();

These utilities simplify authentication checks in Server Components and Server Actions.

6. Create Logout Server Action

Create app/actions/auth.ts using the template from assets/auth-actions.ts. This provides:

Logout action:

  • Clears Supabase session
  • Removes auth cookies
  • Redirects to home page

Use in client components:

import { logout } from '@/app/actions/auth';

<button onClick={() => logout()}>
  Sign Out
</button>

7. Create Login Page

Create app/login/page.tsx using the template from assets/login-page.tsx. This page:

  • Provides email/password login form
  • Handles magic link authentication
  • Supports OAuth providers (Google, GitHub, etc.)
  • Redirects authenticated users
  • Shows error messages

Customize the login page:

  • Add your branding and styling
  • Enable/disable OAuth providers
  • Add password reset link
  • Include sign-up link

8. Create Protected Route Example

Create a protected dashboard page at app/dashboard/page.tsx using the template from assets/dashboard-page.tsx. This demonstrates:

  • Using requireAuth() to protect routes
  • Displaying user information
  • Including logout functionality
  • Server-side authentication check

9. Set Up Callback Route for OAuth

If using OAuth providers, create app/auth/callback/route.ts using the template from assets/auth-callback-route.ts. This handler:

  • Exchanges OAuth code for session
  • Sets secure session cookies
  • Redirects to intended destination
  • Handles OAuth errors

Configure OAuth in Supabase dashboard:

  1. Go to Authentication > Providers
  2. Enable desired providers (Google, GitHub, etc.)
  3. Add redirect URL: https://your-domain.com/auth/callback

Authentication Flow

Login Flow

  1. User visits /login
  2. User enters credentials or clicks OAuth
  3. Supabase authenticates and sets session cookie
  4. User redirected to dashboard or intended page
  5. Middleware validates session on protected routes

Session Refresh Flow

  1. User navigates to any route
  2. Middleware runs and refreshes session if needed
  3. Updated session cookie sent to client
  4. Server Components have access to fresh session

Logout Flow

  1. User clicks logout button
  2. Server Action calls Supabase signOut()
  3. Session and cookies cleared
  4. User redirected to home page

Route Protection Patterns

Protecting Individual Pages

Use requireAuth() at the top of Server Components:

import { requireAuth } from '@/lib/auth/utils';

export default async function ProtectedPage() {
  const user = await requireAuth();

  return <div>Hello {user.email}</div>;
}

Protecting Route Groups

Use Next.js route groups with layout:

// app/(protected)/layout.tsx
import { requireAuth } from '@/lib/auth/utils';

export default async function ProtectedLayout({ children }) {
  await requireAuth();
  return <>{children}</>;
}

All routes in (protected) group are automatically protected.

Optional Authentication

Check if user is logged in without requiring it:

import { getCurrentUser } from '@/lib/auth/utils';

export default async function OptionalAuthPage() {
  const user = await getCurrentUser();

  return (
    <div>
      {user ? `Welcome ${user.email}` : 'Please log in'}
    </div>
  );
}

Server Actions with Authentication

Protect Server Actions using requireAuth():

'use server';

import { requireAuth } from '@/lib/auth/utils';
import { createServerClient } from '@/lib/supabase/server';

export async function updateProfile(formData: FormData) {
  const user = await requireAuth();
  const supabase = createServerClient();

  const { error } = await supabase
    .from('profiles')
    .update({ name: formData.get('name') })
    .eq('id', user.id);

  if (error) throw error;
}

Troubleshooting

Session not persisting: Verify cookies are being set. Check browser dev tools > Application > Cookies. Ensure domain matches.

Middleware redirect loop: Check matcher pattern doesn't include login page. Verify /login is accessible without auth.

OAuth redirect fails: Confirm callback URL matches exactly in Supabase dashboard. Check for trailing slashes.

TypeScript errors: Install types: npm install -D @types/node. Ensure supabase is typed correctly.

401 errors on protected routes: Session may be expired. Check Supabase dashboard > Authentication > Settings for session timeout.

Resources

scripts/

No executable scripts needed for this skill.

references/

  • authentication-patterns.md - Common auth patterns and best practices for Next.js + Supabase
  • security-considerations.md - Security best practices for session handling and cookie configuration

assets/

  • supabase-client.ts - Browser-side Supabase client configuration
  • supabase-server.ts - Server-side Supabase client for Server Components
  • supabase-middleware.ts - Middleware Supabase client for session refresh
  • middleware.ts - Next.js middleware for route protection
  • auth-utils.ts - Helper functions for authentication checks
  • auth-actions.ts - Server Actions for logout and other auth operations
  • login-page.tsx - Complete login page with email/password and OAuth
  • dashboard-page.tsx - Example protected page using requireAuth
  • auth-callback-route.ts - OAuth callback handler for provider authentication

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.35%
按下载量换算48

Claude

28.97%
按下载量换算41

Cursor

21.28%
按下载量换算30

Gemini CLI

9.13%
按下载量换算13

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills