Skip to content

Commit

Permalink
feat: Update authentication domain for Firebase hosting workflows
Browse files Browse the repository at this point in the history
Update the authentication domain in the Firebase hosting workflows to use the correct domain for the production and test branches. This ensures that the authentication functionality works correctly in the deployed application.
  • Loading branch information
Jun-Murakami committed Oct 4, 2024
1 parent c9c78b9 commit 564c1bb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/firebase-hosting-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- run: npm run build
env:
VITE_API_KEY: ${{ secrets.VITE_API_KEY_PROD }}
VITE_AUTH_DOMAIN: ${{ secrets.VITE_AUTH_DOMAIN_PROD }}
VITE_AUTH_DOMAIN: tasktree-s.web.app
VITE_DATABASE_URL: ${{ secrets.VITE_DATABASE_URL_PROD }}
VITE_PROJECT_ID: ${{ secrets.VITE_PROJECT_ID_PROD }}
VITE_STORAGE_BUCKET: ${{ secrets.VITE_STORAGE_BUCKET_PROD }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/firebase-hosting-test-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- run: npm run build
env:
VITE_API_KEY: ${{ secrets.VITE_API_KEY }}
VITE_AUTH_DOMAIN: ${{ secrets.VITE_AUTH_DOMAIN }}
VITE_AUTH_DOMAIN: tasktrees-fb.web.app
VITE_DATABASE_URL: ${{ secrets.VITE_DATABASE_URL }}
VITE_PROJECT_ID: ${{ secrets.VITE_PROJECT_ID }}
VITE_STORAGE_BUCKET: ${{ secrets.VITE_STORAGE_BUCKET }}
Expand Down
53 changes: 38 additions & 15 deletions src/features/homepage/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import {
initializeAuth,
GoogleAuthProvider,
OAuthProvider,
signInWithPopup,
signInWithCredential,
signInWithEmailAndPassword,
createUserWithEmailAndPassword,
sendPasswordResetEmail,
signOut,
Unsubscribe,
signInWithRedirect,
getRedirectResult
} from 'firebase/auth';
import { getDatabase, remove, ref, get, set } from 'firebase/database';
import { getStorage, ref as storageRef, deleteObject, listAll } from 'firebase/storage';
Expand Down Expand Up @@ -119,30 +120,52 @@ export const useAuth = () => {
unsubscribe();
}
};
}, [loginAction, showDialog]);
}, [loginAction, showDialog, setIsLoggedIn, setIsLoading]);

//リダイレクト状態の監視
useEffect(() => {
getRedirectResult(getAuth()).then(async (userCredential) => {
console.log(userCredential);
}).catch((error) => {
console.error(error);
});
}, [setIsLoggedIn, setIsLoading]);

// Googleログイン
const handleGoogleLogin = async () => {
setIsLoading(true);
setSystemMessage('ログイン中...');
// 1. Create credentials on the native layer
try {
const result = await FirebaseAuthentication.signInWithGoogle();
// 2. Sign in on the web layer using the id token
const credential = GoogleAuthProvider.credential(result.credential?.idToken);
await signInWithCredential(auth, credential)
.then(async () => {
if (Capacitor.isNativePlatform() && FirebaseAuthentication) {
// 1. Create credentials on the native layer
try {
const result = await FirebaseAuthentication.signInWithGoogle();
// 2. Sign in on the web layer using the id token
const credential = GoogleAuthProvider.credential(result.credential?.idToken);
await signInWithCredential(auth, credential)
.then(async () => {
setIsLoggedIn(true);
setSystemMessage(null);
})
.catch((error) => {
setSystemMessage('Googleログインに失敗しました。Code:100\n\n' + error.code);
setIsLoading(false);
});
} catch (error) {
setSystemMessage('Googleログインに失敗しました。Code:101\n\n' + error);
setIsLoading(false);
return;
}
} else {
const provider = new OAuthProvider('google.com');
signInWithRedirect(getAuth(), provider)
.then(() => {
setIsLoggedIn(true);
setSystemMessage(null);
})
.catch((error) => {
setSystemMessage('Googleログインに失敗しました。Code:100\n\n' + error.code);
setSystemMessage('Googleログインに失敗しました。Code:102\n\n' + error.code);
setIsLoading(false);
});
} catch (error) {
setSystemMessage('Googleログインに失敗しました。Code:101\n\n' + error);
setIsLoading(false);
return;
}
};

Expand Down Expand Up @@ -178,7 +201,7 @@ export const useAuth = () => {
}
} else {
const provider = new OAuthProvider('apple.com');
signInWithPopup(getAuth(), provider)
signInWithRedirect(getAuth(), provider)
.then(() => {
setIsLoggedIn(true);
setSystemMessage(null);
Expand Down

0 comments on commit 564c1bb

Please sign in to comment.