Compare commits
1 Commits
feat/due-d
...
fix/email-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7418cc37cc |
@@ -1,7 +1,6 @@
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { z } from "zod";
|
||||
|
||||
import { authClient } from "@kan/auth/client";
|
||||
import * as memberRepo from "@kan/db/repository/member.repo";
|
||||
import * as userRepo from "@kan/db/repository/user.repo";
|
||||
import * as workspaceRepo from "@kan/db/repository/workspace.repo";
|
||||
@@ -78,16 +77,15 @@ export const memberRouter = createTRPCRouter({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
});
|
||||
|
||||
const { error } = await authClient.signIn.magicLink({
|
||||
const { status } = await ctx.auth.api.signInMagicLink({
|
||||
email: input.email,
|
||||
callbackURL: `/boards?type=invite&memberPublicId=${invite.publicId}`,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
if (!status) {
|
||||
console.error("Failed to send magic link invitation:", {
|
||||
email: input.email,
|
||||
callbackURL: `/boards?type=invite&memberPublicId=${invite.publicId}`,
|
||||
error,
|
||||
});
|
||||
|
||||
throw new TRPCError({
|
||||
|
||||
@@ -20,58 +20,73 @@ export interface User {
|
||||
stripeCustomerId?: string | null | undefined;
|
||||
}
|
||||
|
||||
const createAuthWithHeaders = (
|
||||
auth: ReturnType<typeof initAuth>,
|
||||
headers: Headers,
|
||||
) => {
|
||||
return {
|
||||
api: {
|
||||
getSession: () => auth.api.getSession({ headers }),
|
||||
signInMagicLink: (input: { email: string; callbackURL: string }) =>
|
||||
auth.api.signInMagicLink({
|
||||
headers,
|
||||
body: { email: input.email, callbackURL: input.callbackURL },
|
||||
}),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
interface CreateContextOptions {
|
||||
user: User | null | undefined;
|
||||
db: dbClient;
|
||||
auth: ReturnType<typeof createAuthWithHeaders>;
|
||||
}
|
||||
|
||||
export const createInnerTRPCContext = (opts: CreateContextOptions) => {
|
||||
return {
|
||||
user: opts.user,
|
||||
db: opts.db,
|
||||
auth: opts.auth,
|
||||
};
|
||||
};
|
||||
|
||||
export const createTRPCContext = async ({ req }: CreateNextContextOptions) => {
|
||||
const db = createDrizzleClient();
|
||||
const auth = initAuth(db);
|
||||
const baseAuth = initAuth(db);
|
||||
const headers = new Headers(req.headers as Record<string, string>);
|
||||
const auth = createAuthWithHeaders(baseAuth, headers);
|
||||
|
||||
const session = await auth.api.getSession({
|
||||
// @ts-expect-error
|
||||
headers: new Headers(req.headers),
|
||||
});
|
||||
const session = await auth.api.getSession();
|
||||
|
||||
return createInnerTRPCContext({ db, user: session?.user });
|
||||
return createInnerTRPCContext({ db, user: session?.user, auth });
|
||||
};
|
||||
|
||||
export const createNextApiContext = async (req: NextApiRequest) => {
|
||||
const db = createDrizzleClient();
|
||||
const auth = initAuth(db);
|
||||
const baseAuth = initAuth(db);
|
||||
const headers = new Headers(req.headers as Record<string, string>);
|
||||
const auth = createAuthWithHeaders(baseAuth, headers);
|
||||
|
||||
const session = await auth.api.getSession({
|
||||
// @ts-expect-error
|
||||
headers: new Headers(req.headers),
|
||||
});
|
||||
const session = await auth.api.getSession();
|
||||
|
||||
return createInnerTRPCContext({ db, user: session?.user });
|
||||
return createInnerTRPCContext({ db, user: session?.user, auth });
|
||||
};
|
||||
|
||||
export const createRESTContext = async ({ req }: CreateNextContextOptions) => {
|
||||
const db = createDrizzleClient();
|
||||
const auth = initAuth(db);
|
||||
const baseAuth = initAuth(db);
|
||||
const headers = new Headers(req.headers as Record<string, string>);
|
||||
const auth = createAuthWithHeaders(baseAuth, headers);
|
||||
|
||||
let session;
|
||||
try {
|
||||
session = await auth.api.getSession({
|
||||
// @ts-expect-error
|
||||
headers: new Headers(req.headers),
|
||||
});
|
||||
session = await auth.api.getSession();
|
||||
} catch (error) {
|
||||
console.error("Error getting session, ", error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
return createInnerTRPCContext({ db, user: session?.user });
|
||||
return createInnerTRPCContext({ db, user: session?.user, auth });
|
||||
};
|
||||
|
||||
const t = initTRPC
|
||||
|
||||
Reference in New Issue
Block a user