feat(db): 🗃️ Add createdAt and updatedAt
This commit is contained in:
@@ -41,7 +41,6 @@ export const CollaborationList = () => {
|
||||
const [invitationEmail, setInvitationEmail] = useState('')
|
||||
const [isSendingInvitation, setIsSendingInvitation] = useState(false)
|
||||
|
||||
console.log(user, owner)
|
||||
const isOwner = user?.email === owner?.email
|
||||
|
||||
const toast = useToast({
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Provider } from 'next-auth/providers'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { withSentry } from '@sentry/nextjs'
|
||||
import { CustomAdapter } from './adapter'
|
||||
import { User } from 'db'
|
||||
|
||||
const providers: Provider[] = [
|
||||
EmailProvider({
|
||||
@@ -56,12 +57,29 @@ const handler = (req: NextApiRequest, res: NextApiResponse) => {
|
||||
strategy: 'database',
|
||||
},
|
||||
callbacks: {
|
||||
session: async ({ session, user }) => ({
|
||||
...session,
|
||||
user,
|
||||
}),
|
||||
session: async ({ session, user }) => {
|
||||
const userFromDb = user as User
|
||||
await updateLastActivityDate(userFromDb)
|
||||
return {
|
||||
...session,
|
||||
userFromDb,
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const updateLastActivityDate = async (user: User) => {
|
||||
const datesAreOnSameDay = (first: Date, second: Date) =>
|
||||
first.getFullYear() === second.getFullYear() &&
|
||||
first.getMonth() === second.getMonth() &&
|
||||
first.getDate() === second.getDate()
|
||||
|
||||
if (!datesAreOnSameDay(user.lastActivityAt, new Date()))
|
||||
await prisma.user.update({
|
||||
where: { id: user.id },
|
||||
data: { lastActivityAt: new Date() },
|
||||
})
|
||||
}
|
||||
|
||||
export default withSentry(handler)
|
||||
|
||||
@@ -24,7 +24,7 @@ export const useCredentials = ({
|
||||
|
||||
export const createCredentials = async (
|
||||
userId: string,
|
||||
credentials: Omit<Credentials, 'ownerId' | 'id' | 'iv'>
|
||||
credentials: Omit<Credentials, 'ownerId' | 'id' | 'iv' | 'createdAt'>
|
||||
) =>
|
||||
sendRequest<{
|
||||
credentials: Credentials
|
||||
|
||||
@@ -12,7 +12,7 @@ export const useCustomDomains = ({
|
||||
onError: (error: Error) => void
|
||||
}) => {
|
||||
const { data, error, mutate } = useSWR<
|
||||
{ customDomains: CustomDomain[] },
|
||||
{ customDomains: Omit<CustomDomain, 'createdAt'>[] },
|
||||
Error
|
||||
>(userId ? `/api/users/${userId}/customDomains` : null, fetcher)
|
||||
if (error) onError(error)
|
||||
@@ -25,7 +25,7 @@ export const useCustomDomains = ({
|
||||
|
||||
export const createCustomDomain = async (
|
||||
userId: string,
|
||||
customDomain: Omit<CustomDomain, 'ownerId'>
|
||||
customDomain: Omit<CustomDomain, 'ownerId' | 'createdAt'>
|
||||
) =>
|
||||
sendRequest<{
|
||||
credentials: Credentials
|
||||
|
||||
Reference in New Issue
Block a user