mirror of
https://github.com/Mail-0/Zero.git
synced 2026-07-01 08:16:28 +00:00
fix: make some endpoints public and return default values (#1110)
## Description `settings.get` and `connection.getDefault` are now public endpoints but they return default data and `null` in case of logged out users, this will fix the issue of UNAUTHORIZED logs being spammed for users who are just on homepage --- ## Type of Change Please delete options that are not relevant. - [ ] 🐛 Bug fix (non-breaking change which fixes an issue) - [ ] ✨ New feature (non-breaking change which adds functionality) - [ ] 💥 Breaking change (fix or feature with breaking changes) - [ ] 📝 Documentation update - [ ] 🎨 UI/UX improvement - [ ] 🔒 Security enhancement - [ ] ⚡ Performance improvement ## Areas Affected Please check all that apply: - [ ] Email Integration (Gmail, IMAP, etc.) - [ ] User Interface/Experience - [ ] Authentication/Authorization - [ ] Data Storage/Management - [ ] API Endpoints - [ ] Documentation - [ ] Testing Infrastructure - [ ] Development Workflow - [ ] Deployment/Infrastructure ## Testing Done Describe the tests you've done: - [ ] Unit tests added/updated - [ ] Integration tests added/updated - [ ] Manual testing performed - [ ] Cross-browser testing (if UI changes) - [ ] Mobile responsiveness verified (if UI changes) ## Security Considerations For changes involving data or authentication: - [ ] No sensitive data is exposed - [ ] Authentication checks are in place - [ ] Input validation is implemented - [ ] Rate limiting is considered (if applicable) ## Checklist - [ ] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document - [ ] My code follows the project's style guidelines - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in complex areas - [ ] I have updated the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix/feature works - [ ] All tests pass locally - [ ] Any dependent changes are merged and published ## Additional Notes Add any other context about the pull request here. ## Screenshots/Recordings Add screenshots or recordings here if applicable. --- _By submitting this pull request, I confirm that my contribution is made under the terms of the project's license._
This commit is contained in:
@@ -42,7 +42,7 @@ export async function loader({ request }: Route.LoaderArgs) {
|
||||
|
||||
const connectionId = await trpc.connections.getDefault
|
||||
.query()
|
||||
.then((res) => res?.id)
|
||||
.then((res) => res?.id ?? null)
|
||||
.catch(() => null);
|
||||
|
||||
return {
|
||||
|
||||
@@ -3,12 +3,12 @@ import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
export const useConnections = () => {
|
||||
const trpc = useTRPC();
|
||||
const connectionsQuery = useQuery(trpc.connections.list.queryOptions(void 0));
|
||||
const connectionsQuery = useQuery(trpc.connections.list.queryOptions());
|
||||
return connectionsQuery;
|
||||
};
|
||||
|
||||
export const useActiveConnection = () => {
|
||||
const trpc = useTRPC();
|
||||
const connectionsQuery = useQuery(trpc.connections.getDefault.queryOptions(void 0));
|
||||
const connectionsQuery = useQuery(trpc.connections.getDefault.queryOptions());
|
||||
return connectionsQuery;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createRateLimiterMiddleware, privateProcedure, router } from '../trpc';
|
||||
import { createRateLimiterMiddleware, privateProcedure, publicProcedure, router } from '../trpc';
|
||||
import { getActiveConnection } from '../../lib/server-utils';
|
||||
import { connection, user as user_ } from '../../db/schema';
|
||||
import { Ratelimit } from '@upstash/ratelimit';
|
||||
@@ -77,7 +77,8 @@ export const connectionsRouter = router({
|
||||
if (connectionId === activeConnection.id)
|
||||
await db.update(user_).set({ defaultConnectionId: null });
|
||||
}),
|
||||
getDefault: privateProcedure.query(async () => {
|
||||
getDefault: publicProcedure.query(async ({ ctx }) => {
|
||||
if (!ctx.session) return null;
|
||||
const connection = await getActiveConnection();
|
||||
return connection;
|
||||
}),
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { createRateLimiterMiddleware, privateProcedure, publicProcedure, router } from '../trpc';
|
||||
import { defaultUserSettings, userSettingsSchema, type UserSettings } from '../../lib/schemas';
|
||||
import { createRateLimiterMiddleware, privateProcedure, router } from '../trpc';
|
||||
import { Ratelimit } from '@upstash/ratelimit';
|
||||
import { userSettings } from '../../db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
export const settingsRouter = router({
|
||||
get: privateProcedure
|
||||
get: publicProcedure
|
||||
.use(
|
||||
createRateLimiterMiddleware({
|
||||
limiter: Ratelimit.slidingWindow(60, '1m'),
|
||||
@@ -13,6 +13,8 @@ export const settingsRouter = router({
|
||||
}),
|
||||
)
|
||||
.query(async ({ ctx }) => {
|
||||
if (!ctx.session) return { settings: defaultUserSettings };
|
||||
|
||||
const { db, session } = ctx;
|
||||
const [result] = await db
|
||||
.select()
|
||||
|
||||
Reference in New Issue
Block a user