fix(auth): small front fixes in 3rd-party auth provider callback

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2023-09-07 11:56:49 +02:00
parent 28c4ae2e48
commit bde7206a1c
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
2 changed files with 20 additions and 12 deletions

View file

@ -80,7 +80,7 @@ export function registerAccount() {
) => {
if (context?.userAlreadyActivated) {
const currentUserData = store.readQuery<{
loggedUser: Pick<ICurrentUser, "actors">;
loggedUser: Pick<ICurrentUser, "actors" | "id">;
}>({
query: IDENTITIES,
});

View file

@ -36,7 +36,10 @@ const userRole = getValueFromMeta("auth-user-role") as ICurrentUserRole;
const router = useRouter();
const { onDone, mutate } = useMutation<
const {
onDone: onUpdateCurrentUserClientDone,
mutate: updateCurrentUserClient,
} = useMutation<
{ updateCurrentUser: ICurrentUser },
{ id: string; email: string; isLoggedIn: boolean; role: ICurrentUserRole }
>(UPDATE_CURRENT_USER_CLIENT);
@ -45,16 +48,19 @@ const { onResult: onLoggedUserResult, load: loadUser } = useLazyQuery<{
loggedUser: IUser;
}>(LOGGED_USER);
onDone(async () => {
onUpdateCurrentUserClientDone(async () => {
loadUser();
onLoggedUserResult(async ({ data: { loggedUser } }) => {
if (loggedUser.defaultActor) {
await changeIdentity(loggedUser.defaultActor);
await router.push({ name: RouteName.HOME });
} else {
// No need to push to REGISTER_PROFILE, the navbar will do it for us
}
});
});
onLoggedUserResult(async (result) => {
if (result.loading) return;
const loggedUser = result.data.loggedUser;
if (loggedUser.defaultActor) {
await changeIdentity(loggedUser.defaultActor);
await router.push({ name: RouteName.HOME });
} else {
// No need to push to REGISTER_PROFILE, the navbar will do it for us
}
});
onMounted(async () => {
@ -67,13 +73,15 @@ onMounted(async () => {
email: userEmail,
role: userRole,
isLoggedIn: true,
defaultActor: undefined,
actors: [],
},
accessToken,
refreshToken,
};
saveUserData(login);
mutate({
updateCurrentUserClient({
id: userId,
email: userEmail,
isLoggedIn: true,