fix: improve onboarding

This commit is contained in:
Carl-Gerhard Lindesvärd
2026-02-27 22:45:21 +01:00
parent b0aa7f4196
commit 10da7d3a1d
25 changed files with 868 additions and 806 deletions

View File

@@ -20,7 +20,6 @@ import {
getUserAccount,
} from '@openpanel/db';
import { sendEmail } from '@openpanel/email';
import { deleteCache } from '@openpanel/redis';
import {
zRequestResetPassword,
zResetPassword,
@@ -81,7 +80,7 @@ export const authRouter = createTRPCRouter({
.input(z.object({ provider: zProvider, inviteId: z.string().nullish() }))
.mutation(async ({ input, ctx }) => {
const isRegistrationAllowed = await getIsRegistrationAllowed(
input.inviteId,
input.inviteId
);
if (!isRegistrationAllowed) {
@@ -137,7 +136,7 @@ export const authRouter = createTRPCRouter({
.input(zSignUpEmail)
.mutation(async ({ input, ctx }) => {
const isRegistrationAllowed = await getIsRegistrationAllowed(
input.inviteId,
input.inviteId
);
if (!isRegistrationAllowed) {
@@ -187,7 +186,7 @@ export const authRouter = createTRPCRouter({
rateLimitMiddleware({
max: 3,
windowMs: 30_000,
}),
})
)
.input(zSignInEmail)
.mutation(async ({ input, ctx }) => {
@@ -210,7 +209,7 @@ export const authRouter = createTRPCRouter({
if (user.account.password?.startsWith('$argon2')) {
const validPassword = await verifyPasswordHash(
user.account.password ?? '',
password,
password
);
if (!validPassword) {
@@ -218,7 +217,7 @@ export const authRouter = createTRPCRouter({
}
} else {
throw TRPCAccessError(
'Reset your password, old password has expired',
'Reset your password, old password has expired'
);
}
}
@@ -226,6 +225,11 @@ export const authRouter = createTRPCRouter({
const token = generateSessionToken();
const session = await createSession(token, user.id);
setSessionTokenCookie(ctx.setCookie, token, session.expiresAt);
ctx.setCookie('last-auth-provider', 'email', {
maxAge: 60 * 60 * 24 * 365,
path: '/',
sameSite: 'lax',
});
return {
type: 'email',
};
@@ -237,7 +241,7 @@ export const authRouter = createTRPCRouter({
rateLimitMiddleware({
max: 3,
windowMs: 60_000,
}),
})
)
.mutation(async ({ input, ctx }) => {
const { token, password } = input;
@@ -275,7 +279,7 @@ export const authRouter = createTRPCRouter({
rateLimitMiddleware({
max: 3,
windowMs: 60_000,
}),
})
)
.input(zRequestResetPassword)
.mutation(async ({ input, ctx }) => {
@@ -324,7 +328,7 @@ export const authRouter = createTRPCRouter({
}),
extendSession: publicProcedure.mutation(async ({ ctx }) => {
if (!ctx.session.session || !ctx.cookies.session) {
if (!(ctx.session.session && ctx.cookies.session)) {
return { extended: false };
}
@@ -348,7 +352,7 @@ export const authRouter = createTRPCRouter({
rateLimitMiddleware({
max: 3,
windowMs: 30_000,
}),
})
)
.input(zSignInShare)
.mutation(async ({ input, ctx }) => {