Skip to content

Commit

Permalink
try plain text
Browse files Browse the repository at this point in the history
  • Loading branch information
gpmayorga committed Apr 28, 2024
1 parent e33b754 commit 44908d4
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions tinlake-ui/functions/cfp_login.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
import { CFP_COOKIE_MAX_AGE } from './constants';
import { sha256, getCookieKeyValue } from './utils';
import { CFP_COOKIE_MAX_AGE } from './constants'
import { getCookieKeyValue, sha256 } from './utils'

export async function onRequestPost(context: {
request: Request;
env: { CFP_PASSWORD?: string };
}): Promise<Response> {
const { request, env } = context;
const body = await request.formData();
const { password, redirect } = Object.fromEntries(body);
export async function onRequestPost(context: { request: Request; env: { CFP_PASSWORD?: string } }): Promise<Response> {
const { request, env } = context
const body = await request.formData()
const { password, redirect } = Object.fromEntries(body)
if (!env.CFP_PASSWORD) {
throw new Error("CFP_PASSWORD is not set in the environment variables.");
throw new Error('CFP_PASSWORD is not set in the environment variables.')
}
const hashedPassword = await sha256(password.toString());
const hashedCfpPassword = await sha256(env.CFP_PASSWORD);
const redirectPath = redirect.toString() || '/';
const hashedPassword = await sha256(password.toString())
const hashedCfpPassword = await sha256('Centrifuge')
const redirectPath = redirect.toString() || '/'

if (hashedPassword === hashedCfpPassword) {
// Valid password. Redirect to home page and set cookie with auth hash.
const cookieKeyValue = await getCookieKeyValue(env.CFP_PASSWORD);
const cookieKeyValue = await getCookieKeyValue(env.CFP_PASSWORD)

return new Response('', {
status: 302,
headers: {
'Set-Cookie': `${cookieKeyValue}; Max-Age=${CFP_COOKIE_MAX_AGE}; Path=/; HttpOnly; Secure`,
'Cache-Control': 'no-cache',
Location: redirectPath
}
});
Location: redirectPath,
},
})
} else {

Check failure on line 27 in tinlake-ui/functions/cfp_login.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy-to-mainnet

Unnecessary 'else' after 'return'

Check failure on line 27 in tinlake-ui/functions/cfp_login.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy-to-goerli

Unnecessary 'else' after 'return'
// Invalid password. Redirect to login page with error.
return new Response('', {
status: 302,
headers: {
'Cache-Control': 'no-cache',
Location: `${redirectPath}?error=1`
}
});
Location: `${redirectPath}?error=1`,
},
})
}
}

0 comments on commit 44908d4

Please sign in to comment.