yes
This commit is contained in:
@@ -49,39 +49,47 @@ export const apiAuthRouter = createTRPCRouter({
|
|||||||
)
|
)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
console.log("[=] Getting new session... ", input);
|
console.log("[=] Getting new session... ", input);
|
||||||
const { captchaId, captchaAnswer } = input;
|
try {
|
||||||
let { userId, userType, password } =
|
const { captchaId, captchaAnswer } = input;
|
||||||
await dbApiUser.getRandomDistributor();
|
let { userId, userType, password } =
|
||||||
if (input.userId) {
|
await dbApiUser.getRandomDistributor();
|
||||||
let _user = await dbApiUser.getUserById(input.userId);
|
if (input.userId) {
|
||||||
console.log("[=] User :: ", _user?.userId);
|
let _user = await dbApiUser.getUserById(input.userId);
|
||||||
if (!_user) {
|
console.log("[=] User :: ", _user?.userId);
|
||||||
|
if (!_user) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
errors: [{ message: "User not found." }],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
userId = _user.userId;
|
||||||
|
userType = _user.userType;
|
||||||
|
password = _user.password;
|
||||||
|
}
|
||||||
|
console.log(`[=] Getting session token for user ${userId}...`);
|
||||||
|
const token = await getSessionToken({
|
||||||
|
code: captchaAnswer,
|
||||||
|
verifyToken: captchaId,
|
||||||
|
userId: userId,
|
||||||
|
userType: userType,
|
||||||
|
password: password,
|
||||||
|
});
|
||||||
|
console.log("[=] Token Response :: ", JSON.stringify(token, null, 2));
|
||||||
|
if (!token.ok) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
errors: [{ message: "User not found." }],
|
errors: [{ message: token.message }],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
userId = _user.userId;
|
await setSessionToRedis(token.message, input.userId ?? "");
|
||||||
userType = _user.userType;
|
return { success: true, errors: [] as ServerError };
|
||||||
password = _user.password;
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
|
message: "Error getting new session.",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
console.log(`[=] Getting session token for user ${userId}...`);
|
|
||||||
const token = await getSessionToken({
|
|
||||||
code: captchaAnswer,
|
|
||||||
verifyToken: captchaId,
|
|
||||||
userId: userId,
|
|
||||||
userType: userType,
|
|
||||||
password: password,
|
|
||||||
});
|
|
||||||
console.log("[=] Token Response :: ", JSON.stringify(token, null, 2));
|
|
||||||
if (!token.ok) {
|
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
errors: [{ message: token.message }],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
await setSessionToRedis(token.message, input.userId ?? "");
|
|
||||||
return { success: true, errors: [] as ServerError };
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
isApiSessionValid: protectedProcedure
|
isApiSessionValid: protectedProcedure
|
||||||
|
|||||||
Reference in New Issue
Block a user