Repository navigation
Expand file tree
/
Copy pathverify.html
More file actions
103 lines (92 loc) · 3.94 KB
/
Copy pathverify.html
File metadata and controls
103 lines (92 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Verify your account • Hapo</title>
<link rel="stylesheet" href="style.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
<script src="config.js"></script>
</head>
<body>
<nav class="nav-header-new">
<div class="nav-container-new">
<div class="nav-brand-new">
<img src="src/lib/images/logo.jpg" alt="Hapo Logo" class="logo-new">
<div class="brand-content-new">
<span class="brand-name-new">Hapo Technology</span>
<span class="brand-tagline-new">Your Money, Your Growth, The Hapo Way!</span>
</div>
</div>
<div class="nav-actions-new">
<button class="student-login-btn-new" onclick="window.location.href='index.html'">Back to Home</button>
</div>
</div>
</nav>
<main class="auth-wrap">
<section class="auth-card">
<h1 class="auth-title">Verify your account</h1>
<p class="auth-subtitle" id="verify-instructions">A 6-digit code was sent to your email address.</p>
<form class="auth-form" id="verify-form">
<div class="field">
<label for="otp">Enter verification code</label>
<input id="otp" name="otp" type="text" inputmode="numeric" maxlength="6" class="input" placeholder="123456" required>
</div>
<button type="submit" class="submit-btn">Verify</button>
<button type="button" class="student-login-btn-new" id="resend-btn" style="margin-top:8px">Resend Code</button>
</form>
</section>
</main>
<script>
const supabase = window.supabase.createClient(window.APP_CONFIG.SUPABASE_URL, window.APP_CONFIG.SUPABASE_KEY);
const email = new URLSearchParams(location.search).get('email');
const instructions = document.getElementById('verify-instructions');
if (email) instructions.textContent = `A 6-digit code was sent to ${email}.`;
document.getElementById('verify-form').addEventListener('submit', async (e) => {
e.preventDefault();
const otp = document.getElementById('otp').value.trim();
try {
const { data: verifyData, error } = await supabase.auth.verifyOtp({ email, token: otp, type: 'email' });
if (error) throw error;
// Ensure we have the current user id
const { data: userData } = await supabase.auth.getUser();
const userId = userData?.user?.id || verifyData?.user?.id;
// If we stored pending profile details, set the password and metadata now
const pendingRaw = sessionStorage.getItem('pending_signup');
if (pendingRaw) {
const pending = JSON.parse(pendingRaw);
// Upsert into public.profiles (works with RLS self-insert/update policies)
if (userId) {
await supabase
.from('profiles')
.upsert({
id: userId,
email,
first_name: pending.firstName || null,
surname: pending.surname || null,
province: pending.province || null,
gender: pending.gender || null,
phone: pending.phone || null
}, { onConflict: 'id' });
}
sessionStorage.removeItem('pending_signup');
}
alert('Email verified! You can now sign in.');
window.location.href = 'parentLogin.html';
} catch (err) {
alert(err.message || 'Verification failed. Try again.');
}
});
document.getElementById('resend-btn').addEventListener('click', async () => {
try {
const { error } = await supabase.auth.signInWithOtp({ email });
if (error) throw error;
alert('Code resent.');
} catch (err) {
alert(err.message || 'Could not resend code.');
}
});
</script>
</body>
</html>