(
auth: Auth,
createProvider: (
scopes?: string[],
customOAuthParameters?: CustomParameters
) => AuthProvider
)
| 115 | }; |
| 116 | |
| 117 | const useSignInWithPopup = ( |
| 118 | auth: Auth, |
| 119 | createProvider: ( |
| 120 | scopes?: string[], |
| 121 | customOAuthParameters?: CustomParameters |
| 122 | ) => AuthProvider |
| 123 | ): SignInWithPopupHook => { |
| 124 | const [error, setError] = useState<AuthError>(); |
| 125 | const [loggedInUser, setLoggedInUser] = useState<UserCredential>(); |
| 126 | const [loading, setLoading] = useState<boolean>(false); |
| 127 | |
| 128 | const doSignInWithPopup = useCallback( |
| 129 | async (scopes?: string[], customOAuthParameters?: CustomParameters) => { |
| 130 | setLoading(true); |
| 131 | setError(undefined); |
| 132 | try { |
| 133 | const provider = createProvider(scopes, customOAuthParameters); |
| 134 | const user = await signInWithPopup(auth, provider); |
| 135 | setLoggedInUser(user); |
| 136 | |
| 137 | return user; |
| 138 | } catch (err) { |
| 139 | setError(err as AuthError); |
| 140 | } finally { |
| 141 | setLoading(false); |
| 142 | } |
| 143 | }, |
| 144 | [auth, createProvider] |
| 145 | ); |
| 146 | |
| 147 | return [doSignInWithPopup, loggedInUser, loading, error]; |
| 148 | }; |
no outgoing calls
no test coverage detected