Skip to content

Commit

Permalink
update sending email in cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
tenkus47 committed Nov 26, 2024
1 parent 3f2f4db commit 77e2db2
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 20 deletions.
8 changes: 3 additions & 5 deletions app/component/utils/getHeaders.server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import getIpAddressByRequest from "~/component/utils/getIpAddress";

export const getHeaders = async (request: Request, token?: string) => {
export const getHeaders = async (request: Request, user?: any) => {
const AccessKey = process.env?.API_ACCESS_KEY;
let ip = getIpAddressByRequest(request);

// Base headers
let headers: Record<string, string> = {
Accept: "application/json",
Expand All @@ -13,9 +12,8 @@ export const getHeaders = async (request: Request, token?: string) => {
"Client-IP": ip,
};

// If a token is passed, add it as a cookie
if (token) {
headers["Cookie"] = `id_token=${token};`;
if (user) {
headers["Cookie"] = `email=${user.emails[0].value};`;
}

return headers;
Expand Down
3 changes: 1 addition & 2 deletions app/routes/api.ocr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const action: ActionFunction = async ({ request }) => {
let URL_File = process.env.API_URL;
let show_coordinate = formdata.get("show_coordinate") as string;
let imageUrl = formdata.get("imageUrl") as string;
const token = user ? user?.id_token : null;
let body = JSON.stringify({
input: imageUrl,
});
Expand All @@ -18,7 +17,7 @@ export const action: ActionFunction = async ({ request }) => {
let res = await fetch(URL_File + "/api/v1/ocr", {
method: "POST",
body,
headers: await getHeaders(request,token),
headers: await getHeaders(request,user),
});

data = await res.json();
Expand Down
3 changes: 1 addition & 2 deletions app/routes/api.stt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ export const action: ActionFunction = async ({ request }) => {
let audioURL = formData.get("audioURL") as string;
let data;
try {
const token = user ? user?.id_token : null;
let body = JSON.stringify({
input: audioURL,
});
let headers = await getHeaders(request,token);
let headers = await getHeaders(request,user);
let response = await fetch(API_URL + "/api/v1/stt", {
method: "POST",
body,
Expand Down
5 changes: 1 addition & 4 deletions app/routes/api.translation.stream.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ export async function loader({ request }: LoaderFunctionArgs) {
if(model==='MONLAM-MELONG'){
api_url = API_URL + "/api/v1/translation/stream";
}


let token=user ? user?.id_token : null;
let body = JSON.stringify({
input: text,
target,
});
let headers = await getHeaders(request,token);
let headers = await getHeaders(request,user);
return fetch(api_url, {
method: "POST",
body,
Expand Down
3 changes: 1 addition & 2 deletions app/routes/api.tts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ export const action: ActionFunction = async ({ request }) => {
let data;
let url = API_URL + "/api/v1/tts";
try {
const token = user ? user?.id_token : null;
const body = JSON.stringify({
input: inputReplace(input_data),
});
const headers = await getHeaders(request,token);
const headers = await getHeaders(request,user);
const response = await fetch(url, {
method: "POST",
body,
Expand Down
5 changes: 1 addition & 4 deletions app/services/auth.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ let auth0Strategy = new Auth0Strategy(
domain: AUTH0_DOMAIN,
},
async ({ accessToken, refreshToken, extraParams, profile }) => {
// Get the user data from your DB or API using the tokens and profile
// // Use the returned information to process or write to the DB.
// //
console.log(refreshToken)

let id_token = extraParams?.id_token;
let expires_on= parseJwt(id_token);
let email = profile?._json?.email;
Expand Down
1 change: 0 additions & 1 deletion app/services/session.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export async function getUserSession(request: Request) {
return user;
}


export async function generateCSRFToken(request: Request, user: any) {
let secretKey = process.env.API_ACCESS_KEY;
let data = !!user ? user : {};
Expand Down

0 comments on commit 77e2db2

Please sign in to comment.