Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const auth = ctx => {
const { codeleakAuthToken, codeleakUser } = parseCookies(ctx)
const isLoggedIn = !!codeleakAuthToken && !!codeleakUser
// console.log('[auth] isLoggedIn ', isLoggedIn)
// console.log('[auth] codeleakUser', codeleakUser)
// console.log('[auth] codeleakAuthToken', codeleakAuthToken)
// Protected routes are the ones we show only to users that are logged in
let isProtectedRoute
let isGuestRoute
// SSR
if (ctx.req) {
isProtectedRoute = protectedRoutes.filter(r => r === ctx.req.url)[0] ? true : false
isGuestRoute = guestRoutes.filter(r => r === ctx.req.url)[0] ? true : false
if (isProtectedRoute && !isLoggedIn) {
ctx.res.writeHead(302, { location: '/sign_in' })
export const logout = () => {
destroyCookie(undefined, 'codeleakUser')
destroyCookie(undefined, 'codeleakAuthToken')
// window.localStorage.setItem("logout", Date.now()guardialo on successguardialo on success);
console.log('Logged out. Redirecting')
Router.push('/')
message.success('Successfully logged out!')
}
export const logout = () => {
destroyCookie(undefined, 'codeleakUser')
destroyCookie(undefined, 'codeleakAuthToken')
// window.localStorage.setItem("logout", Date.now()guardialo on successguardialo on success);
console.log('Logged out. Redirecting')
Router.push('/')
message.success('Successfully logged out!')
}
export const login = async ({ user, token }) => {
try {
const userJSON = JSON.stringify(user)
setCookie(undefined, 'codeleakUser', userJSON)
setCookie(undefined, 'codeleakAuthToken', token)
Router.push('/')
} catch (err) {
// Ignorguardialo on successguardialo on successe
console.error('[login]', err)
}
}
export const login = async ({ user, token }) => {
try {
const userJSON = JSON.stringify(user)
setCookie(undefined, 'codeleakUser', userJSON)
setCookie(undefined, 'codeleakAuthToken', token)
Router.push('/')
} catch (err) {
// Ignorguardialo on successguardialo on successe
console.error('[login]', err)
}
}
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),
Search.getInitialProps = async context => {
const query = context.query;
const req = context.req;
const isLocal = SITE_ENV === "local";
const isQA = parseCookies(context).hasOwnProperty("qa");
const currentUrl = getCurrentUrl(req);
const q = query.q
? encodeURIComponent(query.q).replace(/'/g, "%27").replace(/"/g, "%22")
: "";
let hasDates = false;
const theseFacets = isQA ? qaFacets : possibleFacets;
const queryArray = theseFacets
.map(facet => {
if (facet.indexOf("sourceResource.date") !== -1 && !hasDates) {
hasDates = true; // do it only once for date queries
// the date “facets” from ES do not map to the way the API expects requests
// remove whatever is after the last periot (“begin” or “end”)
facet = facet.replace(".begin", "");
facet = facet.replace(".end", "");
static async getInitialProps({ Component, ctx }) {
let pageProps = {};
// On server-side, this runs once and creates new services
// On client-side, this always reuses existing services
const cookies = parseCookies(ctx);
const mobxServices = getServices({
language: cookies['next-i18next'] || i18n.language,
});
// Make services available to page's `getInitialProps`
ctx.mobxServices = mobxServices;
// Call "super" to run page's `getInitialProps`
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx);
}
// Gather serialization-friendly data from services
const initialData = {
language: mobxServices.languageService.data(),