-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.html
68 lines (62 loc) · 2.56 KB
/
delete.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Delete Account</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<div class="image-section">
<div class="background"></div>
</div>
<div class="form-section">
<h1>Delete Your Account</h1>
<p>Are you sure you want to delete your account? This action is irreversible.</p>
<p id="messages"></p>
<div class="options">
<a href="profile">Go back to profile</a>
</div>
<button id="delete-account">Delete Account</button>
</div>
<script type="module">
import { initializeApp } from 'https://www.gstatic.com/firebasejs/11.0.2/firebase-app.js';
import { getAuth, deleteUser } from 'https://www.gstatic.com/firebasejs/11.0.2/firebase-auth.js';
const firebaseConfig = {
apiKey: "AIzaSyC4guPinRRwZ3AlBdeiZMbn4XKq6_-d1Bo",
authDomain: "auth-test-556c5.firebaseapp.com",
projectId: "auth-test-556c5",
storageBucket: "auth-test-556c5.appspot.com",
messagingSenderId: "274619285634",
appId: "1:274619285634:web:d07e6c6d136041e23b749b"
};
const app = initializeApp(firebaseConfig);
const auth = getAuth();
const deleteAccountButton = document.getElementById('delete-account');
deleteAccountButton.addEventListener('click', (event) => {
event.preventDefault();
const user = auth.currentUser;
if (user) {
deleteUser(user)
.then(() => {
// アカウント削除成功
document.getElementById('messages').textContent = 'アカウントが削除されました。';
// 必要に応じて、ユーザーをログアウトさせたり、ページをリダイレクトさせることができます
auth.signOut();
window.location.href = 'login'; // goodbyeページへリダイレクト
})
.catch((error) => {
// エラーハンドリング
const errorCode = error.code;
const errorMessage = error.message;
document.getElementById('messages').textContent = `エラー: ${errorCode} / ${errorMessage}`;
});
} else {
document.getElementById('messages').textContent = 'ログインしていません。アカウントを削除するにはログインしてください。';
}
});
</script>
</div>
</body>
</html>