Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add signOut #35

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/src/contents/tenant/addTenant.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { signOutUser } from "../../service/auth";
const AddTenant = () => {
return (
<div class="bg-gray-100 h-screen">
Expand All @@ -18,6 +19,10 @@ const AddTenant = () => {
<button
type="button"
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 mx-2 rounded"
onClick={async () => {
await signOutUser();
window.location.href = "/";
}}
yamashita-kenngo marked this conversation as resolved.
Show resolved Hide resolved
>
Logout
</button>
Expand Down
8 changes: 6 additions & 2 deletions app/src/pages/dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSignal, createEffect, Show } from "solid-js";
import { getCurrentUser } from "../service/auth";
import { createSignal, createEffect } from "solid-js";
import { getCurrentUser, signOutUser } from "../service/auth";
import { getDocumentsWithQuery, firestore } from "../service/firestore";
import AccountContent from "../contents/account/accountContent";
import type { QueryObj } from "../service/firestore";
Expand Down Expand Up @@ -29,6 +29,10 @@ const Dashboard = () => {
<button
type="button"
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 mx-2 rounded"
onClick={async () => {
await signOutUser();
window.location.href = "/";
}}
Comment on lines +32 to +35
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ログアウト処理にエラーハンドリングを追加することをお勧めします。

onClick={async () => {
  try {
    await signOutUser();
    window.location.href = "/";
  } catch (error) {
    console.error('Logout failed:', error);
    // Handle error appropriately
  }
}}

>
Logout
</button>
Expand Down
6 changes: 6 additions & 0 deletions app/src/service/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
getAuth,
signInWithEmailAndPassword,
onAuthStateChanged,
signOut
} from "firebase/auth";
import { firebaseApp } from "./firebase";

Expand All @@ -29,6 +30,11 @@ export async function signIn(
return userCredential;
}

// Sign out
export async function signOutUser(): Promise<void> {
await signOut(auth);
}
yamashita-kenngo marked this conversation as resolved.
Show resolved Hide resolved

// check if user is signed in
export async function isVerifiedAccount(): Promise<boolean> {
return new Promise((resolve) => {
Expand Down