user auth register

This commit is contained in:
Aditya Siregar
2025-09-18 01:32:01 +07:00
parent c68b536480
commit 65f61b65cf
24 changed files with 2065 additions and 14 deletions
@@ -0,0 +1,8 @@
-- Remove indexes
DROP INDEX IF EXISTS idx_customers_password_hash;
DROP INDEX IF EXISTS idx_customers_phone_number;
-- Remove added columns
ALTER TABLE customers DROP COLUMN IF EXISTS birth_date;
ALTER TABLE customers DROP COLUMN IF EXISTS phone_number;
ALTER TABLE customers DROP COLUMN IF EXISTS password_hash;
@@ -0,0 +1,9 @@
-- Drop indexes
DROP INDEX IF EXISTS idx_otp_sessions_is_used;
DROP INDEX IF EXISTS idx_otp_sessions_expires_at;
DROP INDEX IF EXISTS idx_otp_sessions_purpose;
DROP INDEX IF EXISTS idx_otp_sessions_phone_number;
DROP INDEX IF EXISTS idx_otp_sessions_token;
-- Drop OTP sessions table
DROP TABLE IF EXISTS otp_sessions;
@@ -0,0 +1,32 @@
-- Create OTP sessions table for storing OTP codes and validation
CREATE TABLE otp_sessions (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
token VARCHAR(255) NOT NULL UNIQUE,
code VARCHAR(10) NOT NULL,
phone_number VARCHAR(20) NOT NULL,
purpose VARCHAR(50) NOT NULL, -- 'login', 'registration', etc.
expires_at TIMESTAMP NOT NULL,
is_used BOOLEAN DEFAULT false,
attempts_count INT DEFAULT 0, -- Track failed attempts
max_attempts INT DEFAULT 3, -- Maximum allowed attempts
created_at TIMESTAMP DEFAULT now(),
updated_at TIMESTAMP DEFAULT now()
);
-- Create indexes for better performance
CREATE INDEX idx_otp_sessions_token ON otp_sessions(token);
CREATE INDEX idx_otp_sessions_phone_number ON otp_sessions(phone_number);
CREATE INDEX idx_otp_sessions_purpose ON otp_sessions(purpose);
CREATE INDEX idx_otp_sessions_expires_at ON otp_sessions(expires_at);
CREATE INDEX idx_otp_sessions_is_used ON otp_sessions(is_used);
-- Add comments
COMMENT ON TABLE otp_sessions IS 'OTP sessions for authentication and registration';
COMMENT ON COLUMN otp_sessions.token IS 'Unique token for OTP session';
COMMENT ON COLUMN otp_sessions.code IS 'OTP code (6-10 digits)';
COMMENT ON COLUMN otp_sessions.phone_number IS 'Target phone number for OTP';
COMMENT ON COLUMN otp_sessions.purpose IS 'Purpose of OTP: login, registration, etc.';
COMMENT ON COLUMN otp_sessions.expires_at IS 'OTP expiration timestamp';
COMMENT ON COLUMN otp_sessions.is_used IS 'Whether OTP has been used';
COMMENT ON COLUMN otp_sessions.attempts_count IS 'Number of failed validation attempts';
COMMENT ON COLUMN otp_sessions.max_attempts IS 'Maximum allowed validation attempts';