Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ResultPage.getInitialProps = async function(context) {
const cookies = nookies.get(context);
let payload = {
fp: cookies['fp'],
se: cookies['se'],
to: cookies['to']
}
let host = "http://localhost:3000"
if (process.env.NODE_ENV === 'production') {
host = "https://pilahpilihpilpres.com"
}
// TODO: Only absolute URL
let result = await fetch(host + `/api/result/get`, {
method: 'POST',
body: JSON.stringify(payload),
async sendAnswers(token) {
const cookies = nookies.get();
let payload = {
fp: cookies['fp'],
se: cookies['se'],
to: cookies['to'],
reCaptcha: token,
answers: this.state.answers
}
let host = "http://localhost:3000"
if (process.env.NODE_ENV === 'production') {
host = "https://pilahpilihpilpres.com"
}
// TODO: Only absolute URL
await fetch(host + `/api/answer/send`, {
Questionnaire.getInitialProps = async function(context) {
const cookies = nookies.get(context);
let payload = {
fp: cookies['fp'],
se: cookies['se'],
to: cookies['to']
}
let host = "http://localhost:3000"
if (process.env.NODE_ENV === 'production') {
host = "https://pilahpilihpilpres.com"
}
// TODO: Only absolute URL
let result = await fetch(host + `/api/question/get`, {
method: 'POST',
body: JSON.stringify(payload),
async getSession(fingerprint) {
const cookies = nookies.get()
let payload = {
fp: fingerprint
}
if (!cookies.hasOwnProperty('se')) {
let result = await fetch(`/api/session/generate`, {
method: 'POST',
body: JSON.stringify(payload),
headers: {
'Content-Type': 'application/json'
}
}).then(res => res.json());
if (result['status'] === 'ok') {
nookies.set({}, 'se', result['session'], {
deleteSession() {
const cookies = nookies.get();
nookies.destroy({}, 'se');
nookies.destroy({}, 'to');
Router.push('/');
}
const getAuthInfo = (ctx?: NextPageContext): Pick => {
const defaultAuthInfo: IAuthInfo = {
email: '',
name: '',
};
let authInfo: string | undefined;
if (isServer) {
authInfo = nookies.get(ctx)[AUTH_INFO];
}
if (isClient) {
authInfo = Cookies.get(AUTH_INFO);
}
try {
return authInfo && JSON.parse(decodeURIComponent(authInfo));
} catch (e) {
return defaultAuthInfo;
}
};
getUserIdentity() {
const Fingerprint2 = require('fingerprintjs2');
const options = {excludes: {userAgent: true}}
const cookies = nookies.get()
if (!cookies.hasOwnProperty('fp')) {
Fingerprint2.get(options, (components) => {
var values = components.map(function (component) { return component.value });
var murmur = Fingerprint2.x64hash128(values.join(''), 31);
nookies.set({}, 'fp', murmur, {
maxAge: 30 * 24 * 60 * 60,
path: '/',
});
this.getSession(murmur);
});
} else {
this.getSession(cookies['fp']);
}
}