Skip to content
This repository was archived by the owner on Aug 30, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import { useAccounts, useCurrentAccount } from "@/stores/account";
import { AccountService } from "@/stores/account/types";
import { log } from "@/utils/logger/logger";
import { useAlert } from "@/providers/AlertProvider";
import { BadgeX } from "lucide-react-native";
import { isExpoGo } from "@/utils/native/expoGoAlert";
import { atobPolyfill, btoaPolyfill } from "js-base64";
import { registerBackgroundTasks } from "@/background/BackgroundTasks";
Expand All @@ -32,6 +34,7 @@
const currentAccount = useCurrentAccount((store) => store.account);
const switchTo = useCurrentAccount((store) => store.switchTo);
const accounts = useAccounts((store) => store.accounts).filter(account => !account.isExternal);
const { showAlert } = useAlert();

const defined = useFlagsStore(state => state.defined);
const [fontsLoaded] = useFonts(getToLoadFonts(defined));
Expand Down Expand Up @@ -76,8 +79,15 @@
);
for (const account of accounts) {
if (account.localID === currentAccount.localID) {
await switchTo(account).catch((error) => {

Check failure on line 82 in App.tsx

View workflow job for this annotation

GitHub Actions / 🛠️ TypeScript and ESLint on Pull Request

Argument of type 'Account' is not assignable to parameter of type 'PrimaryAccount'.
log(`Error during switchTo: ${error}`, "RefreshToken");
if (account.service === AccountService.Pronote) {
showAlert({
title: "Connexion expirée",
message: "Ton compte PRONOTE a expiré, reconnecte-toi.",
icon: <BadgeX />,
});
}
});
break;
}
Expand Down
23 changes: 21 additions & 2 deletions src/services/pronote/reload-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,33 @@ import { Reconnected } from "../reload-account";

export const reloadInstance = async (authentication: PronoteAccount["authentication"]): Promise<Reconnected<PronoteAccount>> => {
const session = pronote.createSessionHandle();
const refresh = await pronote.loginToken(session, authentication);
const tokens = [authentication.token, ...(authentication.oldTokens || [])];
let refresh: pronote.RefreshInformation | undefined;
let lastError: unknown = null;

for (const token of tokens) {
try {
refresh = await pronote.loginToken(session, { ...authentication, token });
break;
} catch (err) {
lastError = err;
}
}

if (!refresh) {
throw lastError || pronote.AuthenticateError;
}

pronote.startPresenceInterval(session);

const uniqueTokens = Array.from(new Set([refresh.token, ...tokens]));

return {
instance: session,
authentication: {
...authentication,
...refresh
...refresh,
oldTokens: uniqueTokens
}
};
};
1 change: 1 addition & 0 deletions src/stores/account/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export interface PronoteAccount extends BaseAccount {

authentication: pronote.RefreshInformation & {
deviceUUID: string;
oldTokens?: string[];
};
identityProvider?: undefined;
providers: string[];
Expand Down
2 changes: 1 addition & 1 deletion src/views/login/pronote/PronoteCredentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const PronoteCredentials: Screen<"PronoteCredentials"> = ({ route, navigation })
last: extract_pronote_name(name).familyName
},

authentication: { ...refresh, deviceUUID: accountID },
authentication: { ...refresh, deviceUUID: accountID, oldTokens: [refresh.token] },
personalization: await defaultPersonalization(session),

identity: {},
Expand Down
2 changes: 1 addition & 1 deletion src/views/login/pronote/PronoteQRCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const PronoteQRCode: Screen<"PronoteQRCode"> = ({ navigation }) => {
last: extract_pronote_name(name).familyName
},

authentication: { ...refresh, deviceUUID: accountID },
authentication: { ...refresh, deviceUUID: accountID, oldTokens: [refresh.token] },
personalization: await defaultPersonalization(session),

identity: {},
Expand Down
2 changes: 1 addition & 1 deletion src/views/login/pronote/PronoteV6Import.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const PronoteV6Import: Screen<"PronoteV6Import"> = ({ route, navigation }) => {
last: extract_pronote_name(name).familyName
},

authentication: { ...refresh, deviceUUID: data.deviceUUID },
authentication: { ...refresh, deviceUUID: data.deviceUUID, oldTokens: [refresh.token] },
personalization: await defaultPersonalization(session),

identity: {},
Expand Down
2 changes: 1 addition & 1 deletion src/views/login/pronote/PronoteWebview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ const PronoteWebview: Screen<"PronoteWebview"> = ({ route, navigation }) => {
last: extract_pronote_name(name).familyName,
},

authentication: { ...refresh, deviceUUID },
authentication: { ...refresh, deviceUUID, oldTokens: [refresh.token] },
personalization: await defaultPersonalization(session),

identity: {},
Expand Down
Loading