return user id and timestamp only

This commit is contained in:
vincanger 2025-02-14 14:17:54 +01:00
parent 4c106fd630
commit 4db607890b
2 changed files with 9 additions and 3 deletions

View File

@ -79,7 +79,7 @@ Authorization on the server-side is the core of your access control logic, and d
You can authorize access to server-side operations by adding a check for a logged-in user on the `context.user` object which is passed to all operations in Wasp:
```tsx title="src/server/actions.ts"
export const updateCurrentUser: UpdateCurrentUser<...> = async (args, context) => {
export const someServerAction: SomeServerAction<...> = async (args, context) => {
if (!context.user) {
throw new HttpError(401); // throw an error if user is not logged in
}

View File

@ -31,7 +31,7 @@ export const updateIsUserAdminById: UpdateIsUserAdminById<{ id: string; data: Pi
return updatedUser;
};
export const updateCurrentUserLastActiveTimestamp: UpdateCurrentUserLastActiveTimestamp<Pick<User, 'lastActiveTimestamp'>, User> = async ({ lastActiveTimestamp }, context) => {
export const updateCurrentUserLastActiveTimestamp: UpdateCurrentUserLastActiveTimestamp<void, Pick<User, 'id' | 'lastActiveTimestamp'>> = async (_args, context) => {
if (!context.user) {
throw new HttpError(401);
}
@ -40,7 +40,13 @@ export const updateCurrentUserLastActiveTimestamp: UpdateCurrentUserLastActiveTi
where: {
id: context.user.id,
},
data: {lastActiveTimestamp},
data: {
lastActiveTimestamp: new Date(),
},
select: {
id: true,
lastActiveTimestamp: true,
},
});
};