Open-source and local-first Slack and Notion alternative that puts you in control of your data
TypeScript chatchat-applicationcrdteditorelectronknowledge-baselocal-firstnotionnotion-alternativerealtime-collaborationself-hostedslacksqliteteam-collaborationwikiyjs
Fix otp code expiresAt parsing (#292)
Hakan Shehu6a90063f0d3e
diff --git a/apps/server/src/api/client/routes/auth/email-password-reset-init.ts b/apps/server/src/api/client/routes/auth/email-password-reset-init.tsindex ff49228b..42235580 100644--- a/apps/server/src/api/client/routes/auth/email-password-reset-init.ts+++ b/apps/server/src/api/client/routes/auth/email-password-reset-init.ts@@ -51,7 +51,7 @@ export const emailPasswordResetInitRoute: FastifyPluginCallbackZod = (const id = generateId(IdType.OtpCode);const expiresAt = new Date(Date.now() + ms(`${config.account.otpTimeout} seconds`)- );+ ).toISOString();const otpCode = generateOtpCode();const account = await databasediff --git a/apps/server/src/lib/accounts.ts b/apps/server/src/lib/accounts.tsindex b6420fdc..fa447a30 100644--- a/apps/server/src/lib/accounts.ts+++ b/apps/server/src/lib/accounts.ts@@ -145,7 +145,7 @@ export const buildLoginVerifyOutput = async (const id = generateId(IdType.OtpCode);const expiresAt = new Date(Date.now() + ms(`${config.account.otpTimeout} seconds`)- );+ ).toISOString();const otpCode = generateOtpCode();const otp: Otp<AccountVerifyOtpAttributes> = {diff --git a/apps/server/src/lib/otps.ts b/apps/server/src/lib/otps.tsindex 5c02cf6d..11a901f8 100644--- a/apps/server/src/lib/otps.ts+++ b/apps/server/src/lib/otps.ts@@ -18,8 +18,9 @@ export const fetchOtp = async <T>(id: string): Promise<Otp<T> | null> => {export const saveOtp = async <T>(id: string, otp: Otp<T>): Promise<void> => {const redisKey = getOtpRedisKey(id);+ const expiresAt = new Date(otp.expiresAt);const expireSeconds = Math.max(- Math.floor((otp.expiresAt.getTime() - Date.now()) / 1000),+ Math.floor((expiresAt.getTime() - Date.now()) / 1000),1);await redis.set(redisKey, JSON.stringify(otp), {diff --git a/apps/server/src/types/otps.ts b/apps/server/src/types/otps.tsindex eb7387fa..ffdb191e 100644--- a/apps/server/src/types/otps.ts+++ b/apps/server/src/types/otps.ts@@ -10,7 +10,7 @@ export type AccountPasswordResetOtpAttributes = {export type Otp<T> = {id: string;- expiresAt: Date;+ expiresAt: string;otp: string;attributes: T;};diff --git a/packages/client/src/mutations/auth/email-password-reset-init.ts b/packages/client/src/mutations/auth/email-password-reset-init.tsindex 19a51bb2..6805ba39 100644--- a/packages/client/src/mutations/auth/email-password-reset-init.ts+++ b/packages/client/src/mutations/auth/email-password-reset-init.ts@@ -6,7 +6,7 @@ export type EmailPasswordResetInitMutationInput = {export type EmailPasswordResetInitMutationOutput = {id: string;- expiresAt: Date;+ expiresAt: string;};declare module '@colanode/client/mutations' {diff --git a/packages/core/src/types/auth.ts b/packages/core/src/types/auth.tsindex 906084a3..80b219e6 100644--- a/packages/core/src/types/auth.ts+++ b/packages/core/src/types/auth.ts@@ -35,7 +35,7 @@ export type LoginSuccessOutput = z.infer<typeof loginSuccessOutputSchema>;export const loginVerifyOutputSchema = z.object({type: z.literal('verify'),id: z.string(),- expiresAt: z.date(),+ expiresAt: z.string(),});export type LoginVerifyOutput = z.infer<typeof loginVerifyOutputSchema>;@@ -82,7 +82,7 @@ export type EmailPasswordResetCompleteInput = z.infer<export const emailPasswordResetInitOutputSchema = z.object({id: z.string(),- expiresAt: z.date(),+ expiresAt: z.string(),});export type EmailPasswordResetInitOutput = z.infer<diff --git a/packages/ui/src/components/auth/email-password-reset-complete-form.tsx b/packages/ui/src/components/auth/email-password-reset-complete-form.tsxindex e3c1bd17..0698b14a 100644--- a/packages/ui/src/components/auth/email-password-reset-complete-form.tsx+++ b/packages/ui/src/components/auth/email-password-reset-complete-form.tsx@@ -32,7 +32,7 @@ const formSchema = z});interface PasswordResetCompleteFormProps {- expiresAt: Date;+ expiresAt: string;isPending: boolean;onSubmit: (values: z.infer<typeof formSchema>) => void;}diff --git a/packages/ui/src/components/auth/email-verify-form.tsx b/packages/ui/src/components/auth/email-verify-form.tsxindex dc2d0547..3c2e471d 100644--- a/packages/ui/src/components/auth/email-verify-form.tsx+++ b/packages/ui/src/components/auth/email-verify-form.tsx@@ -17,7 +17,7 @@ const formSchema = z.object({});interface EmailVerifyFormProps {- expiresAt: Date;+ expiresAt: string;isPending: boolean;onSubmit: (values: z.infer<typeof formSchema>) => void;}diff --git a/packages/ui/src/components/auth/login.tsx b/packages/ui/src/components/auth/login.tsxindex 921ace69..22712713 100644--- a/packages/ui/src/components/auth/login.tsx+++ b/packages/ui/src/components/auth/login.tsx@@ -17,7 +17,7 @@ type LoginState =| {type: 'verify';id: string;- expiresAt: Date;+ expiresAt: string;};export const Login = () => {diff --git a/packages/ui/src/components/auth/register.tsx b/packages/ui/src/components/auth/register.tsxindex 85e182da..e4cc8873 100644--- a/packages/ui/src/components/auth/register.tsx+++ b/packages/ui/src/components/auth/register.tsx@@ -17,7 +17,7 @@ type RegisterState =| {type: 'verify';id: string;- expiresAt: Date;+ expiresAt: string;};export const Register = () => {diff --git a/packages/ui/src/components/auth/reset.tsx b/packages/ui/src/components/auth/reset.tsxindex 8afe67f0..aa4fc98e 100644--- a/packages/ui/src/components/auth/reset.tsx+++ b/packages/ui/src/components/auth/reset.tsx@@ -17,7 +17,7 @@ type ResetState =| {type: 'complete';id: string;- expiresAt: Date;+ expiresAt: string;}| {type: 'success';diff --git a/packages/ui/src/hooks/use-countdown.tsx b/packages/ui/src/hooks/use-countdown.tsxindex a4022e32..06fe744d 100644--- a/packages/ui/src/hooks/use-countdown.tsx+++ b/packages/ui/src/hooks/use-countdown.tsx@@ -7,7 +7,8 @@ const formatTime = (seconds: number): string => {return `This code expires in ${minutes}:${remainingSecs.toString().padStart(2, '0')}`;};-export const useCountdown = (date: Date): [number, string] => {+export const useCountdown = (dateArg: string): [number, string] => {+ const date = new Date(dateArg);const [remainingSeconds, setRemainingSeconds] = useState<number>(0);useEffect(() => {