feat: add authentication, cloud sync, and GDPR compliance
Authentication & Cloud Sync: - Add Supabase integration for auth (email/password, Google, GitHub OAuth) - Add cloud progress sync for logged-in users - Add account deletion feature with confirmation dialog - Auth is optional - anonymous users can still use localStorage UI Improvements: - Add dark-themed account section in sidebar - Show user email in header when logged in - Add signup success feedback message - Update landing page: remove cloud sync from Coming Soon, add Code Challenges - Update benefit text to mention optional cloud sync GDPR Compliance: - Add Privacy Policy dialog with full GDPR-compliant content - Add Imprint dialog with legal contact information - Add footer links for Privacy and Imprint - All legal content translated to 6 languages (en, de, pl, es, ar, uk) Files added: - src/supabase.js - Supabase client with auth and progress sync helpers - src/auth.js - Authentication logic and form handlers - supabase-setup.sql - Database schema and RLS policies
This commit is contained in:
53
supabase-setup.sql
Normal file
53
supabase-setup.sql
Normal file
@@ -0,0 +1,53 @@
|
||||
-- CODE CRISPIES - Supabase Database Setup
|
||||
-- Run this in Supabase Dashboard → SQL Editor → New Query
|
||||
|
||||
-- User progress table
|
||||
CREATE TABLE user_progress (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id UUID REFERENCES auth.users(id) ON DELETE CASCADE,
|
||||
progress JSONB NOT NULL DEFAULT '{}',
|
||||
user_code JSONB NOT NULL DEFAULT '{}',
|
||||
settings JSONB NOT NULL DEFAULT '{}',
|
||||
language TEXT DEFAULT 'en',
|
||||
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
UNIQUE(user_id)
|
||||
);
|
||||
|
||||
-- Newsletter subscribers table
|
||||
CREATE TABLE newsletter_subscribers (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
email TEXT UNIQUE NOT NULL,
|
||||
subscribed_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Row Level Security
|
||||
ALTER TABLE user_progress ENABLE ROW LEVEL SECURITY;
|
||||
ALTER TABLE newsletter_subscribers ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
-- Users can only access their own progress
|
||||
CREATE POLICY "Users can CRUD own progress"
|
||||
ON user_progress FOR ALL
|
||||
USING (auth.uid() = user_id)
|
||||
WITH CHECK (auth.uid() = user_id);
|
||||
|
||||
-- Anyone can subscribe to newsletter (public insert)
|
||||
CREATE POLICY "Anyone can subscribe to newsletter"
|
||||
ON newsletter_subscribers FOR INSERT
|
||||
WITH CHECK (true);
|
||||
|
||||
-- Function to delete own account (called via RPC)
|
||||
CREATE OR REPLACE FUNCTION delete_own_account()
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path = public
|
||||
AS $$
|
||||
BEGIN
|
||||
-- Delete user's progress (CASCADE should handle this, but be explicit)
|
||||
DELETE FROM user_progress WHERE user_id = auth.uid();
|
||||
|
||||
-- Delete the user from auth.users
|
||||
DELETE FROM auth.users WHERE id = auth.uid();
|
||||
END;
|
||||
$$;
|
||||
Reference in New Issue
Block a user