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 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)
}
}
static async getInitialProps(ctx) {
const { req, res, query } = ctx
const alreadyLoggedIn = parseCookies(ctx).loggedIn
const host =
req && req.headers && req.headers.host
? 'http://' + req.headers.host
: window.location.origin
if ((req && req.user) || alreadyLoggedIn) {
if (!alreadyLoggedIn) {
setCookie(ctx, 'loggedIn', true, {
maxAge: 30 * 24 * 60 * 60,
path: '/'
})
}
let displayId = query && query.display
if (!displayId) {
const displayList = await getDisplays(host)
displayId = displayList[0]._id
}
const props = Component.getInitialProps ? await Component.getInitialProps({ ...ctx }) : {}
return {
...props,
displayId,
Object.keys(latestSession).forEach(key => {
setCookie(context, key, latestSession[key], {
path: "/",
maxAge: latestSession.expiration
});
});
}
useEffect(() => {
setCookie({}, 'theme', theme, { path: '/' });
if (document.getElementsByTagName('html')[0].className !== theme) {
document.getElementsByTagName('html')[0].className = theme;
}
}, [theme]);