Skip to content

Commit

Permalink
🐛 keep session and location in the same order
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredkiss3 committed Jan 14, 2024
1 parent 8f18961 commit c7fc9ac
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/app/(app)/settings/sessions/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,20 @@ export default async function SessionListPage() {
async function AllSessions({ userId }: { userId: number }) {
const [currentSesssion, userSessions] = await Promise.all([
getSession(),
Session.getUserSessions(userId)
Session.getUserSessions(userId).then((sessions) =>
Promise.all(
sessions.map(async (session) => {
const location = await getLocationData(session);
return { session, location };
})
)
)
]);
const sessionLocationData = await Promise.all(
userSessions.map(getLocationData)
);

return (
<ul>
{userSessions
.sort((sessionA, sessionB) => {
.sort(({ session: sessionA }, { session: sessionB }) => {
if (sessionA.id === currentSesssion.id) {
return -1;
}
Expand All @@ -125,12 +129,9 @@ async function AllSessions({ userId }: { userId: number }) {
}
return 0;
})
.map((session, index) => {
let location: SuccessfulLocationData | null = null;
const locationData = sessionLocationData[index];
if (locationData.status === "success") {
location = locationData;
}
.map(({ session, location: locationData }, index) => {
const location =
locationData.status === "success" ? locationData : null;

const isActiveSession = session.lastAccessed
? isDateLessThanAnHourAgo(session.lastAccessed)
Expand Down Expand Up @@ -199,6 +200,7 @@ async function AllSessions({ userId }: { userId: number }) {
: session.lastLogin
? `Last login ${formatDate(session.lastLogin)}`
: null}
- {session.id}
</small>
</div>
</div>
Expand Down

0 comments on commit c7fc9ac

Please sign in to comment.