Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beasy-mobile
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
G
beasy-mobile
Commits
53375ad1
Commit
53375ad1
authored
Sep 05, 2025
by
G
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: disable automatic login from old authentication context
parent
3f310bfb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
52 deletions
+51
-52
UserAuthenticationContext.tsx
src/contexts/UserAuthenticationContext.tsx
+51
-52
No files found.
src/contexts/UserAuthenticationContext.tsx
View file @
53375ad1
import
cacheAssetsAsync
from
"@/utils/assetsCache"
;
import
authenticateUser
,
{
parseAuthicationErrors
}
from
"@/utils/requests/authenticateUser"
;
import
type
{
IuserInformations
}
from
"@/utils/requests/types"
;
import
getUserInformations
,
{
parseUserInformationsErrors
,
}
from
"@/utils/requests/userInformations"
;
import
ErrorModal
from
"@components/modals/ErrorModal"
;
import
ErrorModal
from
"@components/modals/ErrorModal"
;
import
{
LOG
}
from
"@logger"
;
import
{
LOG
}
from
"@logger"
;
import
AsyncStorage
from
"@react-native-async-storage/async-storage"
;
import
AsyncStorage
from
"@react-native-async-storage/async-storage"
;
// import { type NavigationProp, useNavigation } from "@react-navigation/native";
import
{
useMutation
}
from
"@tanstack/react-query"
;
import
{
useMutation
}
from
"@tanstack/react-query"
;
import
*
as
SplashScreen
from
"expo-splash-screen"
;
import
*
as
SplashScreen
from
"expo-splash-screen"
;
import
{
createContext
,
useCallback
,
useContext
,
useEffect
,
useState
}
from
"react"
;
import
{
createContext
,
useCallback
,
useContext
,
useState
}
from
"react"
;
// import { type NavigationProp, useNavigation } from "@react-navigation/native";
import
authenticateUser
,
{
parseAuthicationErrors
}
from
"@/utils/requests/authenticateUser"
;
import
type
{
IuserInformations
}
from
"@/utils/requests/types"
;
import
getUserInformations
,
{
parseUserInformationsErrors
,
}
from
"@/utils/requests/userInformations"
;
import
{
useModalsManagerContext
}
from
"./ModalsManagerContext"
;
import
{
useModalsManagerContext
}
from
"./ModalsManagerContext"
;
import
type
{
IauthenticationData
}
from
"./Types"
;
import
type
{
IauthenticationData
}
from
"./Types"
;
...
@@ -69,7 +68,7 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac
...
@@ -69,7 +68,7 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac
access
:
""
,
access
:
""
,
refresh
:
""
,
refresh
:
""
,
});
});
const
[
error
,
setError
]
=
useState
(
""
);
const
[
_
error
,
setError
]
=
useState
(
""
);
const
[
userInformations
,
setUserInformations
]
=
useState
<
IuserInformations
>
({
const
[
userInformations
,
setUserInformations
]
=
useState
<
IuserInformations
>
({
username
:
"JohnDoe"
,
username
:
"JohnDoe"
,
email
:
"JohnDoe@example.com"
,
email
:
"JohnDoe@example.com"
,
...
@@ -120,6 +119,15 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac
...
@@ -120,6 +119,15 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac
},
},
});
});
const
clearStorages
=
useCallback
(
async
()
=>
{
try
{
await
AsyncStorage
.
clear
();
}
catch
(
error
)
{
log
.
error
(
"clearStorages |"
,
JSON
.
stringify
(
error
,
null
,
2
));
// saving error
}
},
[]);
const
userInformationsMutation
=
useMutation
({
const
userInformationsMutation
=
useMutation
({
mutationFn
:
(
userAccessToken
:
string
)
=>
getUserInformations
(
userAccessToken
),
mutationFn
:
(
userAccessToken
:
string
)
=>
getUserInformations
(
userAccessToken
),
onMutate
:
()
=>
{
onMutate
:
()
=>
{
...
@@ -187,7 +195,7 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac
...
@@ -187,7 +195,7 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac
});
});
await
clearStorages
();
await
clearStorages
();
})();
})();
},
[]);
},
[
clearStorages
]);
// Storages
// Storages
...
@@ -209,59 +217,50 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac
...
@@ -209,59 +217,50 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac
}
}
};
};
const
clearStorages
=
async
()
=>
{
const
_loadAuthenticationData
=
async
()
=>
{
try
{
await
AsyncStorage
.
clear
();
}
catch
(
error
)
{
log
.
error
(
"clearStorages |"
,
JSON
.
stringify
(
error
,
null
,
2
));
// saving error
}
};
const
loadAuthenticationData
=
async
()
=>
{
log
.
debug
(
"loadAuthenticationData | Loading authentication data"
);
log
.
debug
(
"loadAuthenticationData | Loading authentication data"
);
const
jsonRepresentation
=
await
AsyncStorage
.
getItem
(
"authenticationData"
);
const
jsonRepresentation
=
await
AsyncStorage
.
getItem
(
"authenticationData"
);
return
jsonRepresentation
?
JSON
.
parse
(
jsonRepresentation
)
:
null
;
return
jsonRepresentation
?
JSON
.
parse
(
jsonRepresentation
)
:
null
;
};
};
const
loadUserInformations
=
async
()
=>
{
const
_
loadUserInformations
=
async
()
=>
{
log
.
debug
(
"loadUserInformations | Loading user informations"
);
log
.
debug
(
"loadUserInformations | Loading user informations"
);
const
jsonRepresentation
=
await
AsyncStorage
.
getItem
(
"userInformations"
);
const
jsonRepresentation
=
await
AsyncStorage
.
getItem
(
"userInformations"
);
return
jsonRepresentation
?
JSON
.
parse
(
jsonRepresentation
)
:
null
;
return
jsonRepresentation
?
JSON
.
parse
(
jsonRepresentation
)
:
null
;
};
};
// biome-ignore lint/correctness/useExhaustiveDependencies: <This should only be executed once. At startup.>
// biome-ignore lint/correctness/useExhaustiveDependencies: <This should only be executed once. At startup.>
useEffect
(()
=>
{
//
useEffect(() => {
log
.
debug
(
"UserAuthenticationContext | App Startup | loading saved user data."
);
//
log.debug("UserAuthenticationContext | App Startup | loading saved user data.");
(
async
()
=>
{
//
(async () => {
try
{
//
try {
// await loadAssetsAsync();
//
// await loadAssetsAsync();
await
cacheAssetsAsync
({
//
await cacheAssetsAsync({
images
:
[
//
images: [
"../assets/background_default.png"
,
//
"../assets/background_default.png",
"../assets/beasy_default.png"
,
//
"../assets/beasy_default.png",
"../assets/beasy_background.png"
,
//
"../assets/beasy_background.png",
"../assets/background_content_white2.png"
,
//
"../assets/background_content_white2.png",
"../../assets/background.png"
,
//
"../../assets/background.png",
],
//
],
});
//
});
const
authenticationData
=
await
loadAuthenticationData
();
//
const authenticationData = await loadAuthenticationData();
const
userInformations
=
await
loadUserInformations
();
//
const userInformations = await loadUserInformations();
if
(
authenticationData
&&
userInformations
)
{
//
if (authenticationData && userInformations) {
setAuthenticationData
(
authenticationData
);
//
setAuthenticationData(authenticationData);
setUserInformations
(
userInformations
);
//
setUserInformations(userInformations);
setIsAuthenticated
(
true
);
//
setIsAuthenticated(true);
}
//
}
}
catch
(
error
)
{
//
} catch (error) {
log
.
error
(
//
log.error(
"UserAuthenticationContext | App Startup | error during retrieval of stored data |"
,
//
"UserAuthenticationContext | App Startup | error during retrieval of stored data |",
JSON
.
stringify
(
error
,
null
,
2
),
//
JSON.stringify(error, null, 2),
);
//
);
}
finally
{
//
} finally {
setTimeout
(
async
()
=>
await
SplashScreen
.
hideAsync
(),
500
);
//
setTimeout(async () => await SplashScreen.hideAsync(), 500);
}
//
}
})();
//
})();
},
[]);
//
}, []);
return
(
return
(
<
UserAuthenticationContext
.
Provider
<
UserAuthenticationContext
.
Provider
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment