Wezter
Wezter
TtRPC
Created by Wezter on 10/9/2022 in #❓-help
Migrating to V10 from V9
It's the only starter that I've found that has implemented screen sharing well between the web and mobile that also use tRPC and DB integration. I'd probably have gone with the t3 turbo starter otherwise.
22 replies
TtRPC
Created by Wezter on 10/9/2022 in #❓-help
Migrating to V10 from V9
I didn't create any of this, I'm just trying to bump a starter someone else created. https://github.com/chamatt/create-kaol-app
22 replies
TtRPC
Created by Wezter on 10/9/2022 in #❓-help
Migrating to V10 from V9
Did you see an issue with my "me" query in the authrouter as well? It previously had a .merge and now it doesn't 🤔
22 replies
TtRPC
Created by Wezter on 10/9/2022 in #❓-help
Migrating to V10 from V9
export const protectedRoute = t.middleware(async (req) => {
const { ctx, next } = req
const user = await getUserFromHeader(ctx.headers)
if (!user) {
throw new TRPCError({
message: `Unauthenticated when trying to access ${ctx.req.url}`,
code: 'UNAUTHORIZED',
})
}
ctx.user = user
ctx.isAdmin = isAdmin(user.role)
return next()
})

export const protectedProcedure = t.procedure.use(protectedRoute)
export const protectedRoute = t.middleware(async (req) => {
const { ctx, next } = req
const user = await getUserFromHeader(ctx.headers)
if (!user) {
throw new TRPCError({
message: `Unauthenticated when trying to access ${ctx.req.url}`,
code: 'UNAUTHORIZED',
})
}
ctx.user = user
ctx.isAdmin = isAdmin(user.role)
return next()
})

export const protectedProcedure = t.procedure.use(protectedRoute)
22 replies
TtRPC
Created by Wezter on 10/9/2022 in #❓-help
Migrating to V10 from V9
@julius Do you see an issue with how I've implemented the me query and do you possibly have a solution for it? Old authRouter:
export const authRouter = createRouter()
.mutation('signIn', {
input: SignInSchema,
resolve: async ({ input: { email, password } }) => {
return signIn({ email, password })
},
})
.mutation('signUp', {
input: SignUpSchema,
resolve: async ({ input: { email, password } }) => {
const user = await signUp({ email, password })
const token = await createSession(user)
return { token }
},
})
.merge(
'me',
protectedRoute.query('', {
resolve: async ({ ctx }) => {
return ctx.user
},
})
)
export const authRouter = createRouter()
.mutation('signIn', {
input: SignInSchema,
resolve: async ({ input: { email, password } }) => {
return signIn({ email, password })
},
})
.mutation('signUp', {
input: SignUpSchema,
resolve: async ({ input: { email, password } }) => {
const user = await signUp({ email, password })
const token = await createSession(user)
return { token }
},
})
.merge(
'me',
protectedRoute.query('', {
resolve: async ({ ctx }) => {
return ctx.user
},
})
)
` New authRouter:
export const authRouter = t.router({
signIn: t.procedure.input(SignInSchema).mutation((req) => {
const { input } = req

return signIn({ email: input.email, password: input.password })
}),
signUp: t.procedure.input(SignUpSchema).mutation(async (req) => {
const input = req.input

const user = await signUp({ email: input.email, password: input.password })
const token = await createSession(user)
return { token }
}),
//This seems wrong:
me: protectedProcedure.query(async (req) => {
const { ctx } = req
return ctx.user
}),
})
export const authRouter = t.router({
signIn: t.procedure.input(SignInSchema).mutation((req) => {
const { input } = req

return signIn({ email: input.email, password: input.password })
}),
signUp: t.procedure.input(SignUpSchema).mutation(async (req) => {
const input = req.input

const user = await signUp({ email: input.email, password: input.password })
const token = await createSession(user)
return { token }
}),
//This seems wrong:
me: protectedProcedure.query(async (req) => {
const { ctx } = req
return ctx.user
}),
})
22 replies
TtRPC
Created by Wezter on 10/9/2022 in #❓-help
Migrating to V10 from V9
ah thanks a lot for the input, I'll hopefully have time to look more at it this weekend. It kinda feels like I've misunderstood how I should update the 'me' query in the authRouter. Before it was a .merge and then a .query and now I only have .query there. https://github.com/chamatt/create-kaol-app/pull/7/files#diff-1737fd1080cbf94128d1b86db71d32f715ff7b0909d374e6de1d71f7a596e3cc
22 replies
TtRPC
Created by Wezter on 10/12/2022 in #❓-help
Mobile app with tRPC
Would you guys say this is a good way to handle it? - Send a x-app-version header with all requests from the mobile app. - If there are any breaking changes in the backend a new version of the API that has breaking changes is created. - The backend will return the old version of the endpoint unless the x-app-version is a version where the fixes have been applied in the mobile app. - Once the new mobile app is live in production either the feature which is affected would be feature toggled or the whole app would be killswitched telling the users to update the app.
4 replies
TtRPC
Created by Wezter on 10/12/2022 in #❓-help
Mobile app with tRPC
Hmm I think I'll have to think on a way to resolve this before we start utilising it for any of our mobile projects 🤔
4 replies
TtRPC
Created by Wezter on 10/8/2022 in #❓-help
Authentication broke after bump to v10 from v9
10 replies
TtRPC
Created by Wezter on 10/8/2022 in #❓-help
Authentication broke after bump to v10 from v9
and you think I should update all the routers before I continue with something else?
10 replies
TtRPC
Created by Wezter on 10/8/2022 in #❓-help
Authentication broke after bump to v10 from v9
10 replies
TtRPC
Created by Wezter on 10/8/2022 in #❓-help
Authentication broke after bump to v10 from v9
Oh I missed that one, thanks a lot! Ran through so many things and that was the only thing I had to do, can't thank you enough! 😄
10 replies