Skip to content

Commit

Permalink
[next] Auth (coralproject#2257)
Browse files Browse the repository at this point in the history
* feat: improved auth features + performance

* fix: auth check logic

* fix: tests
  • Loading branch information
wyattjoh authored and cvle committed Apr 15, 2019
1 parent 3b31e3b commit b63c00f
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 305 deletions.
24 changes: 12 additions & 12 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# excluded because we'll likely need to rebuild this.
node_modules

# static assets are rebuild in the docker container.
dist

# tests are not run in the docker container.
__tests__
coverage

# we won't use the .git folder in production.
.git

# hide the environment config.
.env
# don't include the dependancies
node_modules

# don't include logs.
# don't include any logs
npm-debug.log*

# don't include any yarn files
yarn-error.log
yarn.lock

# hide OS specific files.
# don't include any OS/editor files
.env
.idea/
.vs
.docz
*.swp
*.DS_STORE

# hide generated files.
# don't include any generated files
dist
*.css.d.ts
__generated__

README.md.orig
12 changes: 9 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# don't include the dependancies
node_modules
dist
.env

# don't include any logs
npm-debug.log*

# don't include any yarn files
yarn-error.log
yarn.lock
coverage

# don't include any OS/editor files
.env
.idea/
.vs
.docz
*.swp
*.DS_STORE

# don't include any generated files
dist
*.css.d.ts
__generated__
README.md.orig
14 changes: 1 addition & 13 deletions src/core/client/admin/containers/AuthCheckContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ class AuthCheckContainer extends React.Component<Props> {
}

private hasAccess(props: Props = this.props) {
const {
viewer,
settings: { auth },
} = props.data!;
const { viewer } = props.data!;
if (viewer) {
if (
viewer.role === GQLUSER_ROLE.COMMENTER ||
Expand All @@ -66,15 +63,6 @@ class AuthCheckContainer extends React.Component<Props> {
!can(viewer, props.data.route.data))
) {
return false;
} else if (
!viewer.email ||
!viewer.username ||
(!viewer.profiles.some(p => p.__typename === "LocalProfile") &&
auth.integrations.local.enabled &&
(auth.integrations.local.targetFilter.admin ||
auth.integrations.local.targetFilter.stream))
) {
return false;
}
return true;
}
Expand Down
103 changes: 0 additions & 103 deletions src/core/client/admin/containers/RedirectLoginContainer.tsx

This file was deleted.

15 changes: 0 additions & 15 deletions src/core/client/admin/test/auth/restricted.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,6 @@ it("show restricted screen for commenters and staff", async () => {
}
});

it("show restricted screen when email is not set", async () => {
const { testRenderer } = createTestRenderer({ email: "" });
await waitForElement(() => within(testRenderer.root).getByTestID("authBox"));
});

it("show restricted screen when username is not set", async () => {
const { testRenderer } = createTestRenderer({ username: "" });
await waitForElement(() => within(testRenderer.root).getByTestID("authBox"));
});

it("show restricted screen local was not set (password)", async () => {
const { testRenderer } = createTestRenderer({ profiles: [] });
await waitForElement(() => within(testRenderer.root).getByTestID("authBox"));
});

it("sign out when clicking on sign in as", async () => {
const { context, testRenderer } = createTestRenderer({
role: GQLUSER_ROLE.COMMENTER,
Expand Down
1 change: 1 addition & 0 deletions src/core/client/ui/components/CallOut/CallOut.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
box-sizing: border-box;
border-width: 1px;
border-style: solid;
word-break: break-word;
}

.colorRegular {
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/app/handlers/api/auth/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { validate } from "talk-server/app/request/body";
import { GQLUSER_ROLE } from "talk-server/graph/tenant/schema/__generated__/types";
import { LocalProfile } from "talk-server/models/user";
import { upsert } from "talk-server/services/users";
import { insert } from "talk-server/services/users";
import { Request } from "talk-server/types/express";

export interface SignupBody {
Expand Down Expand Up @@ -65,7 +65,7 @@ export const signupHandler = ({
};

// Create the new user.
const user = await upsert(mongo, tenant, {
const user = await insert(mongo, tenant, {
email,
username,
profiles: [profile],
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/app/handlers/api/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { TenantInstalledAlreadyError } from "talk-server/errors";
import { GQLUSER_ROLE } from "talk-server/graph/tenant/schema/__generated__/types";
import { LocalProfile } from "talk-server/models/user";
import { install, InstallTenant } from "talk-server/services/tenant";
import { upsert, UpsertUser } from "talk-server/services/users";
import { insert, InsertUser } from "talk-server/services/users";
import { RequestHandler } from "talk-server/types/express";

export interface TenantInstallBody {
tenant: Omit<InstallTenant, "domain" | "locale"> & {
locale: LanguageCode | null;
};
user: Required<Pick<UpsertUser, "username" | "email"> & { password: string }>;
user: Required<Pick<InsertUser, "username" | "email"> & { password: string }>;
}

const TenantInstallBodySchema = Joi.object().keys({
Expand Down Expand Up @@ -113,7 +113,7 @@ export const installHandler = ({
};

// Create the first admin user.
await upsert(mongo, tenant, {
await insert(mongo, tenant, {
email,
username,
profiles: [profile],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
FacebookProfile,
retrieveUserWithProfile,
} from "talk-server/models/user";
import { upsert } from "talk-server/services/users";
import { insert } from "talk-server/services/users";

export type FacebookStrategyOptions = OAuth2StrategyOptions;

Expand Down Expand Up @@ -71,7 +71,7 @@ export default class FacebookStrategy extends OAuth2Strategy<
emailVerified = false;
}

user = await upsert(this.mongo, tenant, {
user = await insert(this.mongo, tenant, {
username: displayName,
role: GQLUSER_ROLE.COMMENTER,
email,
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/app/middleware/passport/strategies/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
GoogleProfile,
retrieveUserWithProfile,
} from "talk-server/models/user";
import { upsert } from "talk-server/services/users";
import { insert } from "talk-server/services/users";

export type GoogleStrategyOptions = OAuth2StrategyOptions;

Expand Down Expand Up @@ -70,7 +70,7 @@ export default class GoogleStrategy extends OAuth2Strategy<
emailVerified = false;
}

user = await upsert(this.mongo, tenant, {
user = await insert(this.mongo, tenant, {
username: displayName,
role: GQLUSER_ROLE.COMMENTER,
email,
Expand Down
Loading

0 comments on commit b63c00f

Please sign in to comment.