Skip to main content

authentication

Authentication architecture with email/password, Apple Sign In, Google Sign In, and anonymous guest modes. Covers AuthService as @Observable @MainActor, AuthGuardView gate pattern, optional auth flow, Supabase delegation, and session lifecycle management. Use when implementing user authentication, login flows, or session management in an iOS app.

来源信息

仓库
moasq/nanowave
最近来源活动
2026年3月27日 05:39
检测到的 SKILL.md 语言
英语
星标
32
分支
9

安装方式

默认使用会先检查来源的 Prompt;你也可以切换为直接命令,或下载本地副本。

检查来源文件

决定是否安装前,请先阅读 SKILL.md,以及 SkillsMP 当前展示的配套文件。

文件资源管理器
5 个文件

正在显示 SKILL.md

SKILL.md
来源说明 · 只读预览
name
authentication
description
Authentication architecture with email/password, Apple Sign In, Google Sign In, and anonymous guest modes. Covers AuthService as @Observable @MainActor, AuthGuardView gate pattern, optional auth flow, Supabase delegation, and session lifecycle management. Use when implementing user authentication, login flows, or session management in an iOS app.
# Authentication Architecture ## Auth Method Selection Default is email/password + anonymous guest. Only add other methods when the user explicitly asks: | User Says | Auth Methods | |-----------|-------------| | *(nothing specified)* | email/password + anonymous guest | | "Apple Sign In" / "Sign in with Apple" | Apple Sign In | | "Google Sign In" | Google Sign In (requires GoogleSignIn package) | | "social login" | Apple + Google | | "guest mode" / "browse without account" | anonymous only | Methods combine — a user can request email + Apple + anonymous together. ## Service Architecture `AuthService` is `@Observable @MainActor` — it owns all auth state and lives in `Services/Auth/`, never inside `Features/`. ```swift // ViewModels consume AuthService via init injection @Observable @MainActor class ProfileViewModel { private let authService: AuthService init(authService: AuthService) { self.authService = authService } } // Views access AuthService through @Environment @Environment(AuthService.self) private var authService ``` When the Supabase skill is also loaded, `AuthService` delegates to `SupabaseService.shared.client.auth` for all backend calls. Without a backend skill, `AuthService` uses a placeholder implementation. ## Auth Modes **Gate mode (default):** `AuthGuardView` sits at the app root. Users must authenticate before accessing any content. **Optional mode** (when user says "auth is optional" or "browse without login"): No root gate. Individual features check `authService.isAuthenticated` and prompt login when needed. ## Key Rules - Services live in `Services/Auth/` — never inside `Features/` - ViewModels consume `AuthService` via init injection, never call auth APIs directly - Never manage tokens manually — the backend SDK handles token storage and refresh - Always restore session on app launch - Always handle sign-out gracefully — clear local state even if the server call fails ## References - [Auth Methods](references/auth-methods.md) — email, guest, Apple, Google patterns with Swift code - [Auth Architecture](references/auth-architecture.md) — AuthService, directory structure, environment injection - [Auth Guard](references/auth-guard.md) — gate mode vs optional mode patterns - [Session Security](references/session-security.md) — token lifecycle, sign out, account deletion
在 GitHub 查看