-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* π§ allow for more commands in REDIS * π§ add missing command * β¨ add more commands to webdis * βοΈ fix typo in command name * β¨ add userAgent + device info to session * π fix device information missing for desktop devices * β¨ extend session with user's IP and last login info * β»οΈ combine redirect function with user to automatically get the user * β¨ list all sessions * π·οΈ fix type in middleware * π fixed a bug with session last access not updating correctly * π sort sessions by last access * β¨ revoke active session * π log public IP in middleware * π use CF connecting IP instead of forwarded IP * π log CF IP * β»οΈ pass correct arg into `nextCache` * π keep session and location in the same order * π remove session id log * π fix responsive UI on session page * β»οΈ use get/set instead of hget/hset * β remove superjson as it is not used anymore * π₯ remove unneeded and unused commands * π fix UI break-all * π fix UI on mobile for session detail page * π fix suspense UIs
- Loading branch information
Showing
16 changed files
with
880 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
"use server"; | ||
|
||
import { revalidatePath } from "next/cache"; | ||
import { redirect } from "next/navigation"; | ||
import { withAuth, type AuthState } from "~/actions/middlewares"; | ||
import { nextCache } from "~/lib/server/rsc-utils.server"; | ||
import { Session } from "~/lib/server/session.server"; | ||
import { CacheKeys } from "~/lib/shared/cache-keys.shared"; | ||
import { jsonFetch } from "~/lib/shared/utils.shared"; | ||
|
||
export type SuccessfulLocationData = { | ||
status: "success"; | ||
country: string; | ||
countryCode: string; | ||
region: string; | ||
regionName: string; | ||
city: string; | ||
zip: string; | ||
lat: number; | ||
lon: number; | ||
timezone: string; | ||
isp: string; | ||
org: string; | ||
as: string; | ||
query: string; | ||
}; | ||
export type FailedLocationData = { | ||
status: "fail"; | ||
message: string; | ||
query: string; | ||
}; | ||
export type LocationData = SuccessfulLocationData | FailedLocationData; | ||
|
||
export async function getLocationData(session: Session) { | ||
const fn = nextCache( | ||
(ip: string) => | ||
jsonFetch<LocationData>(`http://ip-api.com/json/${ip}`, { | ||
cache: "force-cache" | ||
}), | ||
{ | ||
tags: CacheKeys.geo(session.ip) | ||
} | ||
); | ||
|
||
return await fn(session.ip); | ||
} | ||
|
||
export const revokeSession = withAuth(async function revokeSession( | ||
sessionId: string, | ||
_: FormData, | ||
{ session: currentSession, currentUser }: AuthState | ||
) { | ||
const foundSesssion = await Session.getUserSession(currentUser.id, sessionId); | ||
|
||
if (!foundSesssion) { | ||
await currentSession.addFlash({ | ||
type: "error", | ||
message: "The session you are trying to revoke is no longer accessible." | ||
}); | ||
} else if (foundSesssion.id === currentSession.id) { | ||
await currentSession.addFlash({ | ||
type: "warning", | ||
message: "You cannot revoke the current active session." | ||
}); | ||
} else { | ||
await Session.endUserSession(currentUser.id, sessionId); | ||
await currentSession.addFlash({ | ||
type: "success", | ||
message: "Session succesfully revoked." | ||
}); | ||
} | ||
|
||
revalidatePath("/"); | ||
redirect("/settings/sessions"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { redirect } from "next/navigation"; | ||
import { redirectIfNotAuthed } from "~/actions/auth.action"; | ||
import { getUserOrRedirect } from "~/actions/auth.action"; | ||
|
||
export default async function Page() { | ||
await redirectIfNotAuthed("/settings/account"); | ||
await getUserOrRedirect("/settings/account"); | ||
redirect("/settings/account"); | ||
} |
Oops, something went wrong.