Skip to content

Commit

Permalink
feat: Add AuthElectronRedirect component for authentication redirect …
Browse files Browse the repository at this point in the history
…handling
  • Loading branch information
Jun-Murakami committed Oct 4, 2024
1 parent 5f93512 commit 1d407dd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/features/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { PrivacyPolicy } from '@/features/app/PrivacyPolicy';
import { Download } from '@/features/app/Download';
import { AuthElectronGoogle } from '@/features/app/AuthElectronGoogle';
import { AuthElectronApple } from '@/features/app/AuthElectronApple';
import { AuthElectronRedirect } from '@/features/app/AuthElectronRedirect';
import { ModalDialog } from '@/features/common/ModalDialog';
import { InputDialog } from '@/features/common/InputDialog';

Expand Down Expand Up @@ -42,6 +43,7 @@ export default function App() {
<Route path='/download' element={<Download />} />
<Route path='/auth/google' element={<AuthElectronGoogle />} />
<Route path='/auth/apple' element={<AuthElectronApple />} />
<Route path='/auth/redirect' element={<AuthElectronRedirect />} />
<Route path='/' element={<HomePage />} />
</Routes>
</Router>
Expand Down
9 changes: 8 additions & 1 deletion src/features/app/AuthElectronApple.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { getAuth, signInWithRedirect, OAuthProvider } from 'firebase/auth';
import { getAuth, signInWithRedirect, OAuthProvider, getRedirectResult } from 'firebase/auth';

const authProvider = localStorage.getItem('auth_provider');

Expand All @@ -9,6 +9,13 @@ export const AuthElectronApple = () => {
localStorage.removeItem('auth_provider');
return;
}
getRedirectResult(getAuth()).then((result) => {
if (result) {
const credential = OAuthProvider.credentialFromResult(result);
const url = '/auth/redirect?credential=' + JSON.stringify(credential);
window.location.href = url;
}
});
const provider = new OAuthProvider('apple.com');
const auth = getAuth();
localStorage.setItem('auth_provider', 'apple');
Expand Down
10 changes: 9 additions & 1 deletion src/features/app/AuthElectronGoogle.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from 'react';
import { getAuth, signInWithRedirect, GoogleAuthProvider } from 'firebase/auth';
import { getAuth, signInWithRedirect, GoogleAuthProvider, getRedirectResult } from 'firebase/auth';

const authProvider = localStorage.getItem('auth_provider');

Expand All @@ -9,6 +9,14 @@ export const AuthElectronGoogle = () => {
localStorage.removeItem('auth_provider');
return;
}
getRedirectResult(getAuth()).then((result) => {
if (result) {
const credential = GoogleAuthProvider.credentialFromResult(result);
const url = '/auth/redirect?credential=' + JSON.stringify(credential);
window.location.href = url;
}
});

const provider = new GoogleAuthProvider();
const auth = getAuth();
localStorage.setItem('auth_provider', 'google');
Expand Down
3 changes: 3 additions & 0 deletions src/features/app/AuthElectronRedirect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const AuthElectronRedirect = () => {
return <>ログインが完了しました。</>;
};

0 comments on commit 1d407dd

Please sign in to comment.