スキル一覧に戻る
Smarter-Poker

authentication-session

by Smarter-Poker

Smarter-Poker-World-Hub

0🍴 0📅 2026年1月26日
GitHubで見るManusで実行

SKILL.md


name: Authentication & Session description: Manage Supabase auth, session persistence, and user state

Authentication & Session Skill

Overview

Handle Supabase authentication, session persistence, and user state management across the Smarter.Poker ecosystem.

Core Principles

Global Auth Handshake

Every page must use the singleton auth pattern:

// In _app.js - SINGLE source of truth
const [session, setSession] = useState(null);
const [isAuthLoading, setIsAuthLoading] = useState(true);

useEffect(() => {
  const initAuth = async () => {
    const { data: { session } } = await supabase.auth.getSession();
    setSession(session);
    setIsAuthLoading(false);
  };
  
  initAuth();
  
  const { data: { subscription } } = supabase.auth.onAuthStateChange((event, session) => {
    setSession(session);
  });
  
  return () => subscription.unsubscribe();
}, []);

CRITICAL: Disable React Strict Mode

React Strict Mode causes double-mounting which breaks Supabase auth:

// next.config.js
module.exports = {
  reactStrictMode: false  // REQUIRED for Supabase auth
};

Session Persistence

Check Logged In

const isLoggedIn = session?.user != null;

Get User Profile

const { data: profile } = await supabase
  .from('profiles')
  .select('*')
  .eq('id', session.user.id)
  .single();

Auth Loading States

Always show loading while auth initializes:

if (isAuthLoading) {
  return <LoadingSpinner />;
}

if (!session) {
  return <LoginPage />;
}

return <AuthenticatedContent />;

Login Flow

Email/Password

const { data, error } = await supabase.auth.signInWithPassword({
  email,
  password
});

OAuth (Google, Discord)

const { data, error } = await supabase.auth.signInWithOAuth({
  provider: 'google',
  options: {
    redirectTo: window.location.origin
  }
});
const { error } = await supabase.auth.signInWithOtp({
  email,
  options: {
    emailRedirectTo: window.location.origin
  }
});

Logout

await supabase.auth.signOut();
// Session state will update via onAuthStateChange

Domain Handling

WWW Redirect (middleware.js)

if (host.startsWith('www.')) {
  return NextResponse.redirect(
    new URL(request.url.replace('www.', ''))
  );
}

Ensure cookies work across subdomains:

const supabase = createClient(url, key, {
  auth: {
    persistSession: true,
    storageKey: 'smarter-poker-auth',
    storage: {
      getItem: (key) => cookies().get(key)?.value,
      setItem: (key, value) => {
        cookies().set(key, value, {
          domain: '.smarter.poker',
          secure: true,
          sameSite: 'lax'
        });
      }
    }
  }
});

Profile Table

CREATE TABLE profiles (
  id UUID PRIMARY KEY REFERENCES auth.users(id),
  username TEXT UNIQUE,
  full_name TEXT,
  avatar_url TEXT,
  display_name_preference TEXT DEFAULT 'username',
  xp INTEGER DEFAULT 0,
  diamonds INTEGER DEFAULT 0,
  created_at TIMESTAMPTZ DEFAULT NOW()
);

Common Issues

"Abort Plague"

Symptom: AbortErrors, session lost on navigation Fix: Disable React Strict Mode

Session Lost on Refresh

Check: Is persistSession: true in Supabase config? Check: Is storage correctly configured?

www vs non-www

Symptom: Logged out when switching domains Fix: Set cookie domain to .smarter.poker

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です