mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 13:04:23 +00:00
Spent a hour fixing the login & registing system & also finding errors
Some checks are pending
Build and Push Docker Image / build-and-push (push) Waiting to run
Some checks are pending
Build and Push Docker Image / build-and-push (push) Waiting to run
in the custom groq api system (also a typo wasted way too much time)
This commit is contained in:
parent
a8d675e2ae
commit
1eb15058d7
3 changed files with 25 additions and 18 deletions
|
@ -11,6 +11,7 @@ export default defineEventHandler(async (event) => {
|
|||
const protocol = getRequestProtocol(event);
|
||||
const slug = getRouterParam(event, "slug");
|
||||
const userToken = getCookie(event, "token") || "";
|
||||
console.log("Token: ", userToken);
|
||||
const doesTheUserHasACustomGroqApiAndWhatIsIt =
|
||||
await checkIfUserHasCustomGroqKey(userToken);
|
||||
let groqClient = groq;
|
||||
|
|
|
@ -46,13 +46,18 @@ export default defineEventHandler(async (event) => {
|
|||
};
|
||||
}
|
||||
const createOtherFields = await sql`
|
||||
insert into user_other_data(user_id, user, translate_enabled, translate_provider, remove_translate_popup)
|
||||
values (${userUUID}, ${username}, false, 'google', false)
|
||||
insert into user_other_data(user_id, username, translate_enabled, translate_provider, remove_translate_popup, starred_news)
|
||||
values (${userUUID}, ${username}, false, 'google', false, '{}'::JSON)
|
||||
`;
|
||||
const newToken = uuidv4();
|
||||
await sql`
|
||||
INSERT INTO usertokens (username, token)
|
||||
VALUES (${username}, ${newToken})
|
||||
`;
|
||||
|
||||
setCookie(event, "token", newToken);
|
||||
return {
|
||||
user: fetchUserInfo,
|
||||
token: newToken,
|
||||
user: fetchUserInfoAgain,
|
||||
};
|
||||
} else {
|
||||
const isValid = await argon2.verify(
|
||||
|
@ -64,19 +69,20 @@ export default defineEventHandler(async (event) => {
|
|||
error: "PASSWORD_NO_MATCH",
|
||||
};
|
||||
}
|
||||
}
|
||||
const newToken = uuidv4();
|
||||
const fetchUserInfoAgain = await sql`
|
||||
select * from users
|
||||
where username = ${username}`;
|
||||
await sql`
|
||||
INSERT INTO usertokens (user, token)
|
||||
VALUES ('${fetchUserInfo[0].username}', '${newToken}')
|
||||
const newToken = uuidv4();
|
||||
const fetchUserInfoAgain = await sql`
|
||||
select * from users
|
||||
where username = ${username}`;
|
||||
await sql`
|
||||
INSERT INTO usertokens (username, token)
|
||||
VALUES (${fetchUserInfoAgain[0].username}, ${newToken})
|
||||
`;
|
||||
setCookie(event, "token", newToken);
|
||||
return {
|
||||
user: fetchUserInfoAgain,
|
||||
};
|
||||
|
||||
setCookie(event, "token", newToken);
|
||||
return {
|
||||
user: fetchUserInfoAgain,
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
return {
|
||||
|
|
|
@ -9,7 +9,7 @@ export async function checkIfUserHasCustomGroqKey(token?: string) {
|
|||
}
|
||||
const checkRealToken = await sql`
|
||||
select * from usertokens
|
||||
where tokens=${token}
|
||||
where token = ${token}
|
||||
`;
|
||||
if (checkRealToken.length === 0) {
|
||||
return {
|
||||
|
@ -28,6 +28,6 @@ export async function checkIfUserHasCustomGroqKey(token?: string) {
|
|||
}
|
||||
return {
|
||||
status: true,
|
||||
customAPi: fetchUserToken[0].groq_api_key,
|
||||
customApi: fetchUserToken[0].groq_api_key,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue