mirror of
https://github.com/usememos/memos.git
synced 2025-11-08 08:21:49 +08:00
chore: update user session table
This commit is contained in:
parent
1fffc41f79
commit
c18d6927ba
3 changed files with 1 additions and 35 deletions
|
|
@ -229,16 +229,6 @@ func (s *APIV1Service) DeleteSession(ctx context.Context, _ *v1pb.DeleteSessionR
|
|||
}
|
||||
}
|
||||
|
||||
// Check if we have an access token (from header-based auth)
|
||||
if accessToken, ok := ctx.Value(accessTokenContextKey).(string); ok && accessToken != "" {
|
||||
// Delete the access token from the store
|
||||
if _, err := s.DeleteUserAccessToken(ctx, &v1pb.DeleteUserAccessTokenRequest{
|
||||
Name: fmt.Sprintf("%s%d/accessTokens/%s", UserNamePrefix, user.ID, accessToken),
|
||||
}); err != nil {
|
||||
slog.Error("failed to delete access token", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := s.clearAuthCookies(ctx); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to clear auth cookies, error: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ const Navigation = observer((props: Props) => {
|
|||
)}
|
||||
>
|
||||
<div className="w-full px-1 py-1 flex flex-col justify-start items-start space-y-2 overflow-auto overflow-x-hidden hide-scrollbar shrink">
|
||||
<NavLink className="mb-2 cursor-default" to={currentUser ? Routes.ROOT : Routes.EXPLORE}>
|
||||
<NavLink className="mb-3 cursor-default" to={currentUser ? Routes.ROOT : Routes.EXPLORE}>
|
||||
<BrandBanner collapsed={collapsed} />
|
||||
</NavLink>
|
||||
{navLinks.map((navLink) => (
|
||||
|
|
|
|||
|
|
@ -60,18 +60,6 @@ const UserSessionsSection = () => {
|
|||
return parts.length > 0 ? parts.join(" • ") : "Unknown Device";
|
||||
};
|
||||
|
||||
const getSessionExpirationDate = (session: UserSession) => {
|
||||
if (!session.lastAccessedTime) return null;
|
||||
// Calculate expiration as last_accessed_time + 2 weeks (14 days)
|
||||
const expirationDate = new Date(session.lastAccessedTime.getTime() + 14 * 24 * 60 * 60 * 1000);
|
||||
return expirationDate;
|
||||
};
|
||||
|
||||
const isSessionExpired = (session: UserSession) => {
|
||||
const expirationDate = getSessionExpirationDate(session);
|
||||
return expirationDate ? expirationDate < new Date() : false;
|
||||
};
|
||||
|
||||
const isCurrentSession = (session: UserSession) => {
|
||||
// A simple heuristic: the most recently accessed session is likely the current one
|
||||
if (userSessions.length === 0) return false;
|
||||
|
|
@ -103,9 +91,6 @@ const UserSessionsSection = () => {
|
|||
<th scope="col" className="px-3 py-2 text-left text-sm font-semibold text-gray-900 dark:text-gray-400">
|
||||
{t("setting.user-sessions-section.last-active")}
|
||||
</th>
|
||||
<th scope="col" className="px-3 py-2 text-left text-sm font-semibold text-gray-900 dark:text-gray-400">
|
||||
{t("setting.user-sessions-section.expires")}
|
||||
</th>
|
||||
<th scope="col" className="relative py-3.5 pl-3 pr-4">
|
||||
<span className="sr-only">{t("common.delete")}</span>
|
||||
</th>
|
||||
|
|
@ -137,15 +122,6 @@ const UserSessionsSection = () => {
|
|||
<span>{userSession.lastAccessedTime?.toLocaleString()}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td className="whitespace-nowrap px-3 py-2 text-sm text-gray-500 dark:text-gray-400">
|
||||
<div className="flex items-center space-x-1">
|
||||
<ClockIcon className="w-4 h-4" />
|
||||
<span>
|
||||
{getSessionExpirationDate(userSession)?.toLocaleString() ?? t("setting.user-sessions-section.never")}
|
||||
{isSessionExpired(userSession) && <span className="ml-2 text-red-600 text-xs">(Expired)</span>}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td className="relative whitespace-nowrap py-2 pl-3 pr-4 text-right text-sm">
|
||||
<Button
|
||||
variant="plain"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue