diff options
author | 2021-09-02 22:28:11 +0200 | |
---|---|---|
committer | 2021-09-02 23:54:56 +0200 | |
commit | f08f6ca0a9d337efff280d4d1669a41b5d9c31c2 (patch) | |
tree | 7dee778ba742deb5f499f2aa08a1ba040606d633 /lib | |
parent | 9f74c550927671f4ded301d0cf3e9d592716375c (diff) | |
download | my_apps-f08f6ca0a9d337efff280d4d1669a41b5d9c31c2.tar.gz my_apps-f08f6ca0a9d337efff280d4d1669a41b5d9c31c2.tar.bz2 my_apps-f08f6ca0a9d337efff280d4d1669a41b5d9c31c2.zip |
finish translations, force maximize
Diffstat (limited to 'lib')
-rw-r--r-- | lib/crypt.js | 19 | ||||
-rw-r--r-- | lib/dbConnect.js | 46 | ||||
-rw-r--r-- | lib/fetchJson.js | 23 | ||||
-rw-r--r-- | lib/sendMail.js | 26 | ||||
-rw-r--r-- | lib/useUser.js | 33 | ||||
-rw-r--r-- | lib/withSession.js | 14 |
6 files changed, 0 insertions, 161 deletions
diff --git a/lib/crypt.js b/lib/crypt.js deleted file mode 100644 index 5d3d79e..0000000 --- a/lib/crypt.js +++ /dev/null @@ -1,19 +0,0 @@ -const crypto = require('crypto') -const algorithm = 'aes-256-ctr' -const secretKey = process.env.MYAPPS_NOTES_KEY - -export const encrypt = (text) => { - const iv = crypto.randomBytes(16) - const cipher = crypto.createCipheriv(algorithm, secretKey, iv) - const encrypted = Buffer.concat([cipher.update(text), cipher.final()]) - - return iv.toString('hex') + '::' + encrypted.toString('hex') -} - -export const decrypt = (hash) => { - const [iv, content] = hash.split('::') - const decipher = crypto.createDecipheriv(algorithm, secretKey, Buffer.from(iv, 'hex')) - const decrpyted = Buffer.concat([decipher.update(Buffer.from(content, 'hex')), decipher.final()]) - - return decrpyted.toString(); -} diff --git a/lib/dbConnect.js b/lib/dbConnect.js deleted file mode 100644 index a58ef79..0000000 --- a/lib/dbConnect.js +++ /dev/null @@ -1,46 +0,0 @@ -import mongoose from 'mongoose' - -// const MONGODB_URI = process.env.MYAPPS_MONGODB_URI -const MONGODB_URI = 'mongodb://localhost:27017/myapps' - -if (!MONGODB_URI) { - throw new Error( - 'Please define the MONGODB_URI environment variable inside .env.local' - ) -} - -/** - * Global is used here to maintain a cached connection across hot reloads - * in development. This prevents connections growing exponentially - * during API Route usage. - */ -let cached = global.mongoose - -if (!cached) { - cached = global.mongoose = {conn: null, promise: null} -} - -async function dbConnect() { - if (cached.conn) { - return cached.conn - } - - if (!cached.promise) { - const opts = { - useNewUrlParser: true, - useUnifiedTopology: true, - bufferCommands: false, - bufferMaxEntries: 0, - useFindAndModify: false, - useCreateIndex: true, - } - - cached.promise = mongoose.connect(MONGODB_URI, opts).then((mongoose) => { - return mongoose - }) - } - cached.conn = await cached.promise - return cached.conn -} - -export default dbConnect diff --git a/lib/fetchJson.js b/lib/fetchJson.js deleted file mode 100644 index 5db80b5..0000000 --- a/lib/fetchJson.js +++ /dev/null @@ -1,23 +0,0 @@ -export default async function fetcher(...args) { - try { - const response = await fetch(...args) - - // if the server replies, there's always some data in json - // if there's a network error, it will throw at the previous line - const data = await response.json() - - if (response.ok) { - return data - } - - const error = new Error(response.statusText) - error.response = response - error.data = data - throw error - } catch (error) { - if (!error.data) { - error.data = {message: error.message} - } - throw error - } -} diff --git a/lib/sendMail.js b/lib/sendMail.js deleted file mode 100644 index f50eaf1..0000000 --- a/lib/sendMail.js +++ /dev/null @@ -1,26 +0,0 @@ -import nodemailer from 'nodemailer' - -const sendMail = (to, subject, text, html) => { - - const transporter = nodemailer.createTransport({ - port: 465, - host: process.env.MYAPPS_MAIL_SMTP_SERVER, - auth: { - user: process.env.MYAPPS_MAIL_ADDRESS, - pass: process.env.MYAPPS_MAIL_PASSWORD, - }, - secure: true, - }) - - const mailData = { - from: `"Notes App" <${process.env.MYAPPS_MAIL_ADDRESS}>`, - to, - subject, - text, - html, - } - - return transporter.sendMail(mailData) -} - -export default sendMail diff --git a/lib/useUser.js b/lib/useUser.js deleted file mode 100644 index 16833aa..0000000 --- a/lib/useUser.js +++ /dev/null @@ -1,33 +0,0 @@ -import { useEffect } from 'react' -import Router from 'next/router' -import useSWR from 'swr' - -export default function useUser({ - redirectToLogin = false, - redirectToVerify = false, - redirectToApps = false, -} = {}) { - const { data: user, mutate: mutateUser } = useSWR('/api/user') - - useEffect(() => { - if (!user || (!redirectToLogin && !redirectToVerify && !redirectToApps)) return - - if (redirectToLogin && !user?.isLoggedIn) { - Router.push('/login') - } - - if (redirectToVerify && user?.isLoggedIn && !user?.isVerified) { - Router.push('/verify') - } - - if ( - (redirectToApps && user?.isLoggedIn && user?.isVerified) - ) { - Router.push('/') - } - - return - }, [user, redirectToLogin, redirectToVerify, redirectToApps]) - - return {user, mutateUser} -} diff --git a/lib/withSession.js b/lib/withSession.js deleted file mode 100644 index 0361db3..0000000 --- a/lib/withSession.js +++ /dev/null @@ -1,14 +0,0 @@ -// this file is a wrapper with defaults to be used in both API routes and `getServerSideProps` functions -import {withIronSession} from 'next-iron-session' - -export default function withSession(handler) { - return withIronSession(handler, { - password: process.env.MYAPPS_SECRET_COOKIE_PASSWORD, - cookieName: 'myapps_session', - cookieOptions: { - // the next line allows to use the session in non-https environments like - // Next.js dev mode (http://localhost:3000) - secure: process.env.NODE_ENV === 'production' ? true : false, - }, - }) -} |