@@ -4,7 +4,7 @@ import {useTranslation} from 'react-i18next';
44import { SuccessErrorBanner } from '../components/SuccessErrorBanner' ;
55import RestAPI from '../dao/RestAPI' ;
66import { BaseNavigatorProps } from '../navigation/NavigationRoutes' ;
7- import { login } from '../redux/features/authSlice' ;
7+ import { login , logout } from '../redux/features/authSlice' ;
88import { useAppDispatch } from '../redux/hooks' ;
99import { LoginBackdrop } from './LoginScreen/LoginBackdrop' ;
1010
@@ -14,6 +14,7 @@ export const AccountActivationScreen = (props: Props) => {
1414 const [ activationError , setActivationError ] = useState ( false ) ;
1515 const [ activationSuccess , setActivationSuccess ] = useState ( false ) ;
1616
17+
1718 const dispatch = useAppDispatch ( ) ;
1819
1920 useEffect ( ( ) => {
@@ -22,13 +23,30 @@ export const AccountActivationScreen = (props: Props) => {
2223 return ;
2324 }
2425
25- RestAPI . activateAccount ( props . route . params . activationId ) . then ( ( ) => {
26- setActivationSuccess ( true ) ;
27- dispatch ( login ( ) ) ;
28- props . navigation . navigate ( 'default' ) ;
29- } ) . catch ( ( ) => {
30- setActivationError ( true ) ;
31- } ) ;
26+ const activationTimer = setTimeout ( ( ) => {
27+ RestAPI . activateAccount ( props . route . params . activationId ) . then ( ( ) => {
28+ setActivationSuccess ( true ) ;
29+ dispatch ( login ( ) ) ;
30+ props . navigation . navigate ( 'default' ) ;
31+ } ) . catch ( ( ) => {
32+ // Sometimes when this sceeen is accessed via deep links, the activity is mounted twice.
33+ // In this case the activation link is already expired. Check if the user is logged in
34+
35+ RestAPI . getUserInfo ( ) . then ( ( userinfo ) => {
36+ if ( userinfo . email ) {
37+ console . info ( 'got userinfo, logging in' ) ;
38+ dispatch ( login ( ) ) ;
39+ props . navigation . navigate ( 'default' ) ;
40+ }
41+ } ) . catch ( ( error ) => {
42+ console . error ( 'Login failed' , error ) ;
43+ dispatch ( logout ( ) ) ;
44+ setActivationError ( true ) ;
45+ } ) ;
46+ } ) ;
47+ } , 1000 ) ;
48+
49+ return ( ( ) => clearTimeout ( activationTimer ) ) ;
3250 } , [ props . route . params . activationId ] ) ;
3351
3452 return (
0 commit comments