const generateUnsubscribeToken = ( userId: string, type: string, dataId: ?string ) => { if (!userId || !type) return null; let token; try { token = jwt.sign( { userId, type, dataId }, process.env.EMAIL_JWT_SIGNATURE, { expiresIn: 60 * 60 * 24 * 7, } ); } catch (err) { return null; } if (!token || token === undefined) { return null; } return token; }
async signup(parent, args, context) { const password = await bcrypt.hash(args.password, 10) const user = await context.prisma.createUser({ ...args, password }) return { token: jwt.sign({ userId: user.id }, process.env.APP_SECRET), user, } }
function getUserId(context) { const Authorization = context.request.get('Authorization') if (Authorization) { const token = Authorization.replace('Bearer ', '') const { userId } = jwt.verify(token, process.env.APP_SECRET) return userId } throw new AuthError() }
async login(parent, { email, password }, context) { const user = await context.prisma.user({ email }) if (!user) { throw new Error(`No user found for email: ${email}`) } const passwordValid = await bcrypt.compare(password, user.password) if (!passwordValid) { throw new Error('Invalid password') } return { token: jwt.sign({ userId: user.id }, process.env.APP_SECRET), user, } }
// FOR RESENDING THE VERIFICATION LINK app.post('/resend_vl', async (req, res) => { let { id } = req.session, [{ username, email }] = await db.query( 'SELECT username, email FROM users WHERE id=?', [id] ), url = `http://localhost:${ process.env.PORT }/deep/most/topmost/activate/${id}`, options = { to: email, subject: 'Activate your Instagam account', html: `<span>Hello ${username}, You received this message because you created an account on Instagram.<span><br><span>Click on button below to activate your account and explore.</span><br><br><a href='${url}' style='border: 1px solid #1b9be9; font-weight: 600; color: #fff; border-radius: 3px; cursor: pointer; outline: none; background: #1b9be9; padding: 4px 15px; display: inline-block; text-decoration: none;'>Activate</a>`, } try { await mail(options) res.json({ mssg: 'Verification link sent to your email!!' }) } catch (error) { res.json({ mssg: 'Mail could not be sent!!' }) } })
process.env.PORT }/deep/most/topmost/activate/${insertId}`, options = {
async action({ next }) { // Execute each child route until one of them return the result const route = await next(); // Provide default values for title, description etc. route.title = `${route.title || 'Untitled Page'} - ${process.env.APP_NAME}`; route.description = route.description || ''; return route; }
constructor(code: string | number, ...interpolations: Array<any>) { if (process.env.NODE_ENV === 'production') { super( `An error occurred. See https://github.com/styled-components/styled-components/blob/master/packages/styled-components/src/utils/errors.md#${code} for more information.${ interpolations.length > 0 ? ` Additional arguments: ${interpolations.join(', ')}` : '' }` ); } else { super(format(ERRORS[code], ...interpolations).trim()); } }
// Error handler app.use((err, req, res, next) => { logger.error(err.message, { code: err.code, stack: err.stack }); // logger.console('test'); const message = process.env.NODE_ENV !== 'production' ? err.message : 'An error encountered while processing'; res.status(500).json({ message }); return next(); });
(process.env.NODE_PATH || '') .split(path.delimiter) .filter(folder => folder && !path.isAbsolute(folder)) .map(folder => path.resolve(appDirectory, folder)) .join(path.delimiter)
setNativeProps(nativeProps: Object) { if (this.root !== undefined) { // $FlowFixMe this.root.setNativeProps(nativeProps); } else if (process.env.NODE_ENV !== 'production') { // eslint-disable-next-line no-console console.warn( 'setNativeProps was called on a Styled Component wrapping a stateless functional component.' ); } }
const installExtensions = async () => { const installer = require('electron-devtools-installer'); const forceDownload = !!process.env.UPGRADE_EXTENSIONS; const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS']; return Promise.all( extensions.map(name => installer.default(installer[name], forceDownload)), ).catch(console.log); }
/* istanbul ignore next */ router.get('/', (req, res) => { if (process.env.NODE_ENV === 'production') { const render = require('server/render').default; const page = render(); return res.send(page); } const template = require('client/index.html'); const CONSTANT = require('client/constant'); const page = template.replace('"-- CONFIG --"', JSON.stringify(CONSTANT)); return res.send(page); });
async function getBrowser() { if (!browser) { browser = await puppeteer.launch({ timeout: 120000, args: process.env.TRAVIS || process.env.CHROME_NO_SANDBOX ? ["--no-sandbox"] // https://docs.travis-ci.com/user/chrome#Sandboxing : [] }); } return browser; }
const generateEmailValidationToken = ( userId: string, email: string, communityId?: string ) => { if (!userId || !email) return null; let token; try { token = jwt.sign( { userId, email, communityId }, process.env.EMAIL_JWT_SIGNATURE, { expiresIn: 60 * 60 * 24 * 7, } ); } catch (err) { return null; } if (!token || token === undefined) { return null; } return token; }