Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static async getInitialProps({req, res, query}) {
let props = await super.getInitialProps({req})
props.session = await NextAuth.init({force: true, req: req})
props.providers = await NextAuth.providers({req})
// If signed in already, redirect to account management page.
if (props.session.user) {
if (req) {
res.redirect('/account')
} else {
Router.push('/account')
}
}
// If passed a redirect parameter, save it as a cookie
if (query.redirect) {
const cookies = new Cookies((req && req.headers.cookie) ? req.headers.cookie : null)
cookies.set('redirect_url', query.redirect, { path: '/' })
}
static async getInitialProps({req, res, query}) {
const props = await super.getInitialProps({req});
const session = await NextAuth.init({force: true, req: req});
props.user = userFromSession(session);
props.providers = await NextAuth.providers({req});
// If signed in already, redirect to account management page.
if (props.user.authenticated) {
if (req) {
res.redirect('/account');
} else {
Router.push('/account');
}
}
// If passed a redirect parameter, save it as a cookie
if (query.redirect) {
const cookies = new Cookies((req && req.headers.cookie) ? req.headers.cookie : null);
cookies.set('redirect_url', query.redirect, { path: '/' });
}
async toggleModal(e) {
if (e) e.preventDefault()
// Save current URL so user is redirected back here after signing in
if (this.state.modal !== true) {
const cookies = new Cookies()
cookies.set('redirect_url', window.location.pathname, { path: '/' })
}
this.setState({
providers: this.state.providers || await NextAuth.providers(),
modal: !this.state.modal
})
}
static async getInitialProps({req}) {
return {
session: await NextAuth.init({req}),
linkedAccounts: await NextAuth.linked({req}),
providers: await NextAuth.providers({req})
}
}
static async getInitialProps({req}) {
return {
session: await NextAuth.init({req}),
linkedAccounts: await NextAuth.linked({req}),
providers: await NextAuth.providers({req})
}
}