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}) {
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: '/' });
static async getInitialProps({req, res, query}) {
let props = await super.getInitialProps({req})
props.session = await NextAuth.init({force: true, req: req})
// If signed in already, instead of displaying message send to callback page
// which should redirect them to whatever page it normally sends clients to
if (props.session.user) {
if (req) {
res.redirect('/auth/callback')
} else {
Router.push('/auth/callback')
}
}
props.email = query.email
return props
}
async componentDidMount() {
const session = await NextAuth.init({ force: true })
this.setState({
user: userFromSession(session),
csrfToken: session.csrfToken
})
// If the user bounces off to link/unlink their account we want them to
// land back here after signing in with the other service / unlinking.
const cookies = new Cookies()
cookies.set('redirect_url', window.location.pathname, { path: '/' })
}
async componentDidMount() {
// Get latest session data after rendering on client *then* redirect.
// The ensures client state is always updated after signing in or out.
// (That's why we use a callback page)
const session = await NextAuth.init({force: true})
Router.push(this.props.redirectTo || '/')
}
static async getInitialProps({req}) {
const session = await NextAuth.init({force: true, req: req})
const cookies = new Cookies((req && req.headers.cookie) ? req.headers.cookie : null)
// If the user is signed in, we look for a redirect URL cookie and send
// them to that page, so that people signing in end up back on the page they
// were on before signing in. Defaults to '/'.
let redirectTo = '/'
if (session.user) {
// Read redirect URL to redirect to from cookies
redirectTo = cookies.get('redirect_url') || redirectTo
// Allow relative paths only - strip protocol/host/port if they exist.
redirectTo = redirectTo.replace( /^[a-zA-Z]{3,5}\:\/{2}[a-zA-Z0-9_.:-]+\//, '')
}
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}) {
return {
session: await NextAuth.init({req})
}
}
static async getInitialProps({req}) {
return {
session: await NextAuth.init({force: true, req: req})
}
}
static async getInitialProps({req, query}) {
const session = await NextAuth.init({req});
return {
user: userFromSession(session),
csrfToken: session.csrfToken,
lang: 'en',
query
};
}
}
static async getInitialProps({req}) {
return {
session: await NextAuth.init({req}),
linkedAccounts: await NextAuth.linked({req}),
providers: await NextAuth.providers({req})
}
}