Ayush Goyal
Ayush Goyal
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Ayush Goyal on 8/12/2024 in #questions
applying migrations...Error: getaddrinfo ENOTFOUND postgres
Hi Guys , I am using nextjs app router with drizzle with postgres and its working fine in development mode but when i am running it with docker compose up --build its giving me this error
[⣷] applying migrations...Error: getaddrinfo ENOTFOUND postgres
1.013 at /app/node_modules/pg-pool/index.js:45:11
1.013 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
1.013 at PgDialect.migrate (/app/node_modules/src/pg-core/dialect.ts:72:3)
1.013 at migrate (/app/node_modules/src/node-postgres/migrator.ts:10:2) {
1.013 errno: -3008,
1.013 code: 'ENOTFOUND',
1.013 syscall: 'getaddrinfo',
1.013 hostname: 'postgres'
1.013 }
[⣷] applying migrations...Error: getaddrinfo ENOTFOUND postgres
1.013 at /app/node_modules/pg-pool/index.js:45:11
1.013 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
1.013 at PgDialect.migrate (/app/node_modules/src/pg-core/dialect.ts:72:3)
1.013 at migrate (/app/node_modules/src/node-postgres/migrator.ts:10:2) {
1.013 errno: -3008,
1.013 code: 'ENOTFOUND',
1.013 syscall: 'getaddrinfo',
1.013 hostname: 'postgres'
1.013 }
the whole code can be found in this repo https://github.com/AyushiitrFreedom/bountpirac
2 replies
TTCTheo's Typesafe Cult
Created by Ayush Goyal on 9/1/2023 in #questions
React query Refetching on page change
let { data: orders, isLoading, isFetching, isError, error, refetch } = trpc.order.getallcart.useQuery(undefined, { retry: 1 });
let { data: orders, isLoading, isFetching, isError, error, refetch } = trpc.order.getallcart.useQuery(undefined, { retry: 1 });
I am using this code ( react query + trpc) , i want whenever i change links , router , the query should rerun and new data should come from the database but it is not happening , i tried various refetching methods but none of them worked , anyone who can suggest something
3 replies
TTCTheo's Typesafe Cult
Created by Ayush Goyal on 8/19/2023 in #questions
TrPC + Express + Next 13
src/app/api/trpc/[trpc]/route.ts
import {
FetchCreateContextFnOptions,
fetchRequestHandler,
} from "@trpc/server/adapters/fetch";
import { appRouter } from "../trpc-router";

const handler = (request: Request) => {
console.log(`incoming request ${request.url}`);
return fetchRequestHandler({
endpoint: "/api/trpc",
req: request,
router: appRouter,
createContext: function (
opts: FetchCreateContextFnOptions
): object | Promise<object> {
return {};
},
});
};

export { handler as GET, handler as POST };
import {
FetchCreateContextFnOptions,
fetchRequestHandler,
} from "@trpc/server/adapters/fetch";
import { appRouter } from "../trpc-router";

const handler = (request: Request) => {
console.log(`incoming request ${request.url}`);
return fetchRequestHandler({
endpoint: "/api/trpc",
req: request,
router: appRouter,
createContext: function (
opts: FetchCreateContextFnOptions
): object | Promise<object> {
return {};
},
});
};

export { handler as GET, handler as POST };
This is the way you add trpc to Next13 , but how can i achieve this if i am using Express js in my backend
3 replies
TTCTheo's Typesafe Cult
Created by Ayush Goyal on 8/11/2023 in #questions
Trpc google authentication passport
const GoogleAuth = middleware(async (opts) => {
passport.authenticate('google', { failureRedirect: '/login', successRedirect: '/protected' })
return opts.next()
});

google: googleProcedure.query(async (opts) => {
console.log(opts);
}),
const GoogleAuth = middleware(async (opts) => {
passport.authenticate('google', { failureRedirect: '/login', successRedirect: '/protected' })
return opts.next()
});

google: googleProcedure.query(async (opts) => {
console.log(opts);
}),
I am using passport js but i don't know why my code is not working like its not taking me to google signup
2 replies
TTCTheo's Typesafe Cult
Created by Ayush Goyal on 8/9/2023 in #questions
Typescript with jwt passport
import { Strategy as JwtStrategy, ExtractJwt } from 'passport-jwt';
import passport from 'passport';

const opts = {};


opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
opts.secretOrKey = 'Random string';

passport.use(new JwtStrategy(opts, function (jwt_payload, done) {
UserModel.findOne({ id: jwt_payload.id }, function (err, user) {
if (err) {
return done(err, false);
}
if (user) {
return done(null, user);
} else {
return done(null, false);
// or you could create a new account
}
});
}));
import { Strategy as JwtStrategy, ExtractJwt } from 'passport-jwt';
import passport from 'passport';

const opts = {};


opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
opts.secretOrKey = 'Random string';

passport.use(new JwtStrategy(opts, function (jwt_payload, done) {
UserModel.findOne({ id: jwt_payload.id }, function (err, user) {
if (err) {
return done(err, false);
}
if (user) {
return done(null, user);
} else {
return done(null, false);
// or you could create a new account
}
});
}));
I have this code with me , how do i write in typescript , what do you guys do . I know typescript but i feel that there are many places i will miss typesafety
2 replies
TTCTheo's Typesafe Cult
Created by Ayush Goyal on 8/8/2023 in #questions
how to access Nested routes
export const appRouter = t.router({
show: t.procedure.query(async () => {
const cities: Cities[] = await db.select().from(city);
return cities;
}),

auth: authRouter,
})
export const appRouter = t.router({
show: t.procedure.query(async () => {
const cities: Cities[] = await db.select().from(city);
return cities;
}),

auth: authRouter,
})
export const authRouter = t.router({
log: t.procedure.query(async () => {
const cities: Cities[] = await db.select().from(city);
return cities;
})

})
export const authRouter = t.router({
log: t.procedure.query(async () => {
const cities: Cities[] = await db.select().from(city);
return cities;
})

})
when i visit localhost:5000/show , it works but when i visit localhost:5000/auth/log , it does not work anyone who can help me ?
2 replies