chore: Move to prettier standard double quotes (#1309)

This commit is contained in:
Tom Moor
2020-06-20 13:59:15 -07:00
committed by GitHub
parent 2a3b9e2104
commit f43deb7940
444 changed files with 5988 additions and 5977 deletions

View File

@ -1,20 +1,20 @@
// @flow
import JWT from 'jsonwebtoken';
import { type Context } from 'koa';
import { User, ApiKey } from '../models';
import { getUserForJWT } from '../utils/jwt';
import { AuthenticationError, UserSuspendedError } from '../errors';
import addMonths from 'date-fns/add_months';
import addMinutes from 'date-fns/add_minutes';
import { getCookieDomain } from '../../shared/utils/domains';
import JWT from "jsonwebtoken";
import { type Context } from "koa";
import { User, ApiKey } from "../models";
import { getUserForJWT } from "../utils/jwt";
import { AuthenticationError, UserSuspendedError } from "../errors";
import addMonths from "date-fns/add_months";
import addMinutes from "date-fns/add_minutes";
import { getCookieDomain } from "../../shared/utils/domains";
export default function auth(options?: { required?: boolean } = {}) {
return async function authMiddleware(ctx: Context, next: () => Promise<*>) {
let token;
const authorizationHeader = ctx.request.get('authorization');
const authorizationHeader = ctx.request.get("authorization");
if (authorizationHeader) {
const parts = authorizationHeader.split(' ');
const parts = authorizationHeader.split(" ");
if (parts.length === 2) {
const scheme = parts[0];
const credentials = parts[1];
@ -33,11 +33,11 @@ export default function auth(options?: { required?: boolean } = {}) {
} else if (ctx.request.query.token) {
token = ctx.request.query.token;
} else {
token = ctx.cookies.get('accessToken');
token = ctx.cookies.get("accessToken");
}
if (!token && options.required !== false) {
throw new AuthenticationError('Authentication required');
throw new AuthenticationError("Authentication required");
}
let user;
@ -52,13 +52,13 @@ export default function auth(options?: { required?: boolean } = {}) {
},
});
} catch (e) {
throw new AuthenticationError('Invalid API key');
throw new AuthenticationError("Invalid API key");
}
if (!apiKey) throw new AuthenticationError('Invalid API key');
if (!apiKey) throw new AuthenticationError("Invalid API key");
user = await User.findByPk(apiKey.userId);
if (!user) throw new AuthenticationError('Invalid API key');
if (!user) throw new AuthenticationError("Invalid API key");
} else {
// JWT
user = await getUserForJWT(token);
@ -83,7 +83,7 @@ export default function auth(options?: { required?: boolean } = {}) {
ctx.signIn = async (user, team, service, isFirstSignin = false) => {
if (user.isSuspended) {
return ctx.redirect('/?notice=suspended');
return ctx.redirect("/?notice=suspended");
}
// update the database when the user last signed in
@ -94,18 +94,18 @@ export default function auth(options?: { required?: boolean } = {}) {
// set a cookie for which service we last signed in with. This is
// only used to display a UI hint for the user for next time
ctx.cookies.set('lastSignedIn', service, {
ctx.cookies.set("lastSignedIn", service, {
httpOnly: false,
expires: new Date('2100'),
expires: new Date("2100"),
domain,
});
// set a transfer cookie for the access token itself and redirect
// to the teams subdomain if subdomains are enabled
if (process.env.SUBDOMAINS_ENABLED === 'true' && team.subdomain) {
if (process.env.SUBDOMAINS_ENABLED === "true" && team.subdomain) {
// get any existing sessions (teams signed in) and add this team
const existing = JSON.parse(
decodeURIComponent(ctx.cookies.get('sessions') || '') || '{}'
decodeURIComponent(ctx.cookies.get("sessions") || "") || "{}"
);
const sessions = encodeURIComponent(
JSON.stringify({
@ -117,24 +117,24 @@ export default function auth(options?: { required?: boolean } = {}) {
},
})
);
ctx.cookies.set('sessions', sessions, {
ctx.cookies.set("sessions", sessions, {
httpOnly: false,
expires,
domain,
});
ctx.cookies.set('accessToken', user.getJwtToken(), {
ctx.cookies.set("accessToken", user.getJwtToken(), {
httpOnly: true,
expires: addMinutes(new Date(), 1),
domain,
});
ctx.redirect(`${team.url}/auth/redirect`);
} else {
ctx.cookies.set('accessToken', user.getJwtToken(), {
ctx.cookies.set("accessToken", user.getJwtToken(), {
httpOnly: false,
expires,
});
ctx.redirect(`${team.url}/home${isFirstSignin ? '?welcome' : ''}`);
ctx.redirect(`${team.url}/home${isFirstSignin ? "?welcome" : ""}`);
}
};