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

Androidでユーザー作成→ログインが動作していない #189

Merged
merged 4 commits into from May 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Router.tsx
Expand Up @@ -24,13 +24,20 @@ import Contact from 'components/pages/Contact';
const Stack = createStackNavigator<RootStackParamList>();
const prefix = Linking.createURL('/');

console.log('prefix', prefix);

const WithProvider = () => {
return (
<NavigationContainer
linking={{
prefixes: [prefix],
subscribe(listener) {
const onReceiveURL = ({ url }: { url: string }) => {
console.log('onReceiveURL', url);
if (url.includes('expo-auth-session')) {
// ログインかたらコールバックは一致しないのでreturnする
return;
}
listener(url);
};

Expand All @@ -41,6 +48,7 @@ const WithProvider = () => {
(response) => {
const url =
response.notification.request.content.data?.urlScheme ?? '';
console.log('Notifications URL:', url);

if (url !== '') {
listener(`${prefix}${url}`);
Expand Down
13 changes: 11 additions & 2 deletions src/hooks/useFirebaseAuth.tsx
Expand Up @@ -19,6 +19,7 @@ import {
useExistAuthUserLazyQuery,
useUserLazyQuery,
} from 'queries/api/index';
import usePrevious from 'hooks/usePrevious';

const auth = new Auth();

Expand Down Expand Up @@ -118,6 +119,8 @@ const useFirebaseAuth = (login = false, errorCallback?: () => void) => {
const [request, response, promptAsync] =
Google.useIdTokenAuthRequest(authParam);

const prevResponseType = usePrevious(response?.type || null);

const onGoogleLogin = useCallback(() => {
promptAsync();
}, [promptAsync]);
Expand Down Expand Up @@ -159,7 +162,13 @@ const useFirebaseAuth = (login = false, errorCallback?: () => void) => {
);

useEffect(() => {
if (response?.type === 'success' && !user.id) {
console.log('useEffect:', response, authUser.uid);

if (
response?.type === 'success' &&
prevResponseType !== 'success' &&
!authUser.uid
Copy link
Owner Author

Choose a reason for hiding this comment

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

!user.idのif文が間違い。正しくは認証済みかを判定

) {
const { id_token } = response.params;
const credential = firebase.auth.GoogleAuthProvider.credential(id_token);
firebaseLogin(credential);
Expand All @@ -168,7 +177,7 @@ const useFirebaseAuth = (login = false, errorCallback?: () => void) => {
Alert.alert('ログインに失敗しました');
errorCallback?.();
}
}, [response, firebaseLogin, errorCallback, user.id]);
}, [response, prevResponseType, firebaseLogin, errorCallback, authUser.uid]);

const onAppleLogin = useCallback(async () => {
const nonce = nonceGen(32);
Expand Down