Authentication in Ionic Angular with Supabase
An Ionic Angular realtime messaging app built on Supabase demonstrates email/password signup and login, magic link authentication for web and native mobile, and route protection with Angular guards. The Postgres side defines users, groups and messages tables, adds Row Level Security policies so the public anon key is safe in the frontend, uses a security-definer trigger to copy new auth users into a public table, and publishes the messages table for realtime inserts. On the client, an AuthService wraps supabase.auth and tracks session state in an RxJS BehaviorSubject, loading the stored session with getUser() at startup because onAuthStateChange usually doesn't fire on app load. Most of the logic applies to any Angular web project.
Related posts
- Building a Realtime Trello Board with Supabase and Angular
Supabase mediumAdeptA Trello-style board clone built on Supabase, Angular and Tailwind, with boards, lists and cards stored in Postgres tables. Access is secured with Row Level Security policies backed by a security-definer function that returns the current user's boards. Triggers auto-link new boards to their creator and mirror auth users into a public users table, and setting replica identity full lets realtime subscriptions see deleted rows. The Angular side covers magic link sign-in through an RxJS BehaviorSubject auth service, routing, and realtime updates, with full source on GitHub.
- supabase-js v2
Supabase mediumAdeptsupabase-js v2 brings incremental quality-of-life changes over v1. Types are now generated from the database via the CLI and set once on the client. signIn() is split into signInWithPassword() and signInWithOtp(), server-side auth moves to auth.admin, and the auth library is now async to fix a multi-tab token refresh race condition that logged users out. insert/update/upsert no longer return data unless select() is appended, which avoids surprise failures under Row Level Security. Constructor config is scoped per sub-library, each sub-library gets typed errors, Edge Function invocations auto-detect content type, and a new channel() API replaces from().on() for realtime and Postgres change subscriptions. v1 gets security and maintenance patches for three months.
- Flutter Authorization with RLS
Supabase mediumAdeptExtends a basic Flutter real-time chat app into a 1-on-1 chat with authorization enforced by PostgreSQL Row Level Security on Supabase. The schema adds rooms and room_participants tables, a room_id foreign key on messages, and a security-definer plpgsql function create_new_room that returns an existing room for two users or creates one. The client side uses flutter_bloc cubits to stream room participants and each room's latest message via Supabase realtime. Email confirmation is handled through deep links configured in iOS Info.plist, AndroidManifest.xml and the Supabase redirect URL settings.
- Supabase Auth: SSO, Mobile, and Server-side support
Supabase mediumAdeptSupabase Auth adds SAML 2.0 single sign-on, a PKCE authorization flow for server-side rendering and mobile apps, and native Sign in with Apple on iOS. SSO providers are managed with new `supabase sso` CLI commands, and the provider identifier in the JWT can drive Postgres Row Level Security policies for multi-tenant isolation. PKCE replaces the implicit grant flow, which exposed tokens in URL fragments that servers can't read and that malicious mobile apps could intercept. It does this with a hashed code verifier and challenge, so an intercepted authorization code is useless on its own. Enabling it means setting `flowType: 'pkce'` in supabase-js, and a Next.js callback route exchanges the code for a session.
- Supabase Auth: Identity Linking, Hooks, and HaveIBeenPwned integration
Supabase mediumAdeptSupabase Auth adds four features: manual Identity Linking via linkIdentity()/unlinkIdentity() for OAuth identities, session controls (time-boxed sessions, inactivity timeouts, single session per user on Pro and above), leaked password protection using the HaveIBeenPwned Pwned Passwords API with configurable password requirements, and Auth Hooks. Auth Hooks are Postgres functions that run synchronously at points such as access token generation, MFA verification and password verification, so they can add custom JWT claims or enforce custom security rules. Webhook-based hooks via Standard Webhooks are planned for Q1 2024. The GoTrue fork is also being renamed to Auth, with no breaking changes.