(Cloudflare) Workers CPU resources exceeded

Hello everyone, I have a web app made using SvelteKit and am facing this issue where my cpu resources are being exceeded while signing in or up, i.e the limit of 10ms CPU time is not enough for these auth purposes, now is there any way to avoid this or only upgrading to paid plans can make it avoid this problem? I have two alternatives or workaround I can use: - Create a different server for this sole purpose, i.e a deno server which signs in, parses the cookie sends back to our main app - Migrate to something like Vercel. Is the first solution viable and vulnerable to security concerns? Currently this is the code am using:

default: async ({ request, cookies }) => {
let body = await request.formData()
let email = body.get('email') as string
let password = body.get('password') as string

try {
let res = await auth.api.signInEmail({
body: {
email,
password
},
asResponse: true
});


const setCookieHeader = res.headers.get('set-cookie');

if (setCookieHeader) {
const valueIndex = setCookieHeader.indexOf('=');
const semicolonIndex = setCookieHeader.indexOf(';');
const encodedValue = setCookieHeader.slice(
valueIndex + 1,
semicolonIndex > -1 ? semicolonIndex : undefined
);
const decodedValue = decodeURIComponent(encodedValue);

cookies.set('better-auth.session_token', decodedValue, {
path: '/',
httpOnly: true,
maxAge: 604800,
sameSite: 'lax'
});
} else {
return fail(500, { internalServerError: "Something went wrong while signing in" })
}
}catch(){
//other code
}
}

default: async ({ request, cookies }) => {
let body = await request.formData()
let email = body.get('email') as string
let password = body.get('password') as string

try {
let res = await auth.api.signInEmail({
body: {
email,
password
},
asResponse: true
});


const setCookieHeader = res.headers.get('set-cookie');

if (setCookieHeader) {
const valueIndex = setCookieHeader.indexOf('=');
const semicolonIndex = setCookieHeader.indexOf(';');
const encodedValue = setCookieHeader.slice(
valueIndex + 1,
semicolonIndex > -1 ? semicolonIndex : undefined
);
const decodedValue = decodeURIComponent(encodedValue);

cookies.set('better-auth.session_token', decodedValue, {
path: '/',
httpOnly: true,
maxAge: 604800,
sameSite: 'lax'
});
} else {
return fail(500, { internalServerError: "Something went wrong while signing in" })
}
}catch(){
//other code
}
}
Help would be really appreciated, Thanks.
1 Reply
SheldonFromBBT
SheldonFromBBTOP6d ago
Even using client auth doesnt solve this issue. This happens only while signing in with email and password method

Did you find this page helpful?