11import { useLocalSearchParams } from "expo-router" ;
2- import React , { useEffect , useRef } from "react" ;
2+ import React , { useEffect , useRef , useState } from "react" ;
33import { Alert , SafeAreaView , StyleSheet } from "react-native" ;
44import { AuthWebView , AuthWebViewRef } from "../components/AuthWebView" ;
55import FloatingActionButton from "../components/FloatingActionButton" ;
@@ -23,6 +23,7 @@ export default function DashboardScreen() {
2323 const isBiometricLogin = params . biometricLogin === "true" ;
2424
2525 const webViewRef = useRef < AuthWebViewRef > ( null ) ;
26+ const [ credentialsSaved , setCredentialsSaved ] = useState ( false ) ;
2627
2728 // Use hooks for state management
2829 const authStateHook = useAuthState ( {
@@ -42,36 +43,35 @@ export default function DashboardScreen() {
4243 formCapture . setFormCredentials ( credentials ) ;
4344 } ,
4445 onSessionExtracted : async ( sessionData ) => {
45- console . log ( "🔔 [Dashboard] Session extracted successfully" ) ;
46+ // Create token from session and login
47+ const tokenResponse =
48+ webViewMessages . createSessionTokenResponse ( sessionData ) ;
49+ handleLoginSuccess ( tokenResponse ) ;
50+ authStateHook . setIsLoggingIn ( false ) ;
4651
47- // Save login credentials if available
48- if ( authState . isAuthenticated ) {
52+ // Save login credentials if available - AFTER handleLoginSuccess sets isAuthenticated = true
53+ if ( ! credentialsSaved ) {
4954 const credentialsForSaving =
5055 formCapture . getCredentialsForSaving ( isBiometricLogin ) ;
56+
5157 if ( credentialsForSaving ) {
5258 await biometricAuth . promptToStoreCredentials ( credentialsForSaving ) ;
59+ setCredentialsSaved ( true ) ; // Oznacz że dane zostały zapisane
5360 }
5461 }
55-
56- // Create token from session and login
57- const tokenResponse =
58- webViewMessages . createSessionTokenResponse ( sessionData ) ;
59- handleLoginSuccess ( tokenResponse ) ;
60- authStateHook . setIsLoggingIn ( false ) ;
6162 } ,
6263 onSessionExtractionError : ( error ) => {
6364 console . error ( "🔔 [Dashboard] Session extraction error:" , error ) ;
6465 } ,
6566 } ) ;
6667
67- // Inicjalizacja OAuth dla normalnego logowania
6868 useEffect ( ( ) => {
6969 if ( isLoginMode && ! isBiometricLogin && ! authState . isAuthenticated ) {
70+ setCredentialsSaved ( false ) ;
7071 oauth . initializeAuth ( ) ;
7172 }
7273 } , [ isLoginMode , isBiometricLogin , authState . isAuthenticated ] ) ;
7374
74- // Inicjalizacja logowania biometrycznego
7575 useEffect ( ( ) => {
7676 if ( isBiometricLogin && ! authState . isAuthenticated ) {
7777 initializeBiometricAuth ( ) ;
@@ -86,9 +86,6 @@ export default function DashboardScreen() {
8686 if ( credentials ) {
8787 formCapture . setBiometricCredentials ( credentials ) ;
8888 await oauth . initializeAuth ( ) ;
89- console . log (
90- "🔐 [Dashboard] Gotowe do automatycznego uzupełniania formularza"
91- ) ;
9289 } else {
9390 Alert . alert (
9491 "Brak danych" ,
@@ -113,23 +110,19 @@ export default function DashboardScreen() {
113110 return ;
114111 }
115112
116- // Sprawdź callback OAuth2
117113 if ( oauth . isCallbackUrl ( navState . url ) ) {
118- console . log ( "🌐 [Dashboard] Detected OAuth callback" ) ;
119-
120114 const success = await oauth . handleAuthCallback ( navState . url ) ;
121115
122116 if ( success ) {
123117 authStateHook . setIsLoggingIn ( false ) ;
124118
125- // Zapisz dane logowania po udanym logowaniu
126119 const credentialsForSaving =
127120 formCapture . getCredentialsForSaving ( isBiometricLogin ) ;
121+
128122 if ( credentialsForSaving ) {
129123 await biometricAuth . promptToStoreCredentials ( credentialsForSaving ) ;
130124 }
131125
132- // Przekieruj do dashboardu inFakt
133126 setTimeout ( ( ) => {
134127 const redirectScript = createRedirectScript (
135128 "https://front.sandbox-infakt.pl"
@@ -174,7 +167,6 @@ export default function DashboardScreen() {
174167 setTimeout ( ( ) => {
175168 authStateHook . handleLogout ( ) ;
176169
177- // Przekieruj do strony głównej inFakt
178170 const redirectScript = createRedirectScript (
179171 "https://front.sandbox-infakt.pl"
180172 ) ;
@@ -186,15 +178,13 @@ export default function DashboardScreen() {
186178 }
187179 } ;
188180
189- // Określ URL do załadowania
190181 const webViewUrl =
191182 authStateHook . isLoggingIn && oauth . authUrl
192183 ? oauth . authUrl
193184 : "https://front.sandbox-infakt.pl" ;
194185
195186 return (
196187 < SafeAreaView style = { styles . container } >
197- { /* Navigation bar - hide in login mode */ }
198188 { ! authStateHook . isLoggingIn && authState . isAuthenticated && (
199189 < NavigationBar
200190 canGoBack = { authStateHook . canGoBack }
@@ -206,7 +196,6 @@ export default function DashboardScreen() {
206196 />
207197 ) }
208198
209- { /* Login bar */ }
210199 { authStateHook . isLoggingIn && (
211200 < LoginBar
212201 isBiometricLogin = { isBiometricLogin }
0 commit comments