Skip to content

Commit

Permalink
Merge branch 'dev' into docker-builds
Browse files Browse the repository at this point in the history
* dev: (66 commits)
  Make doctoc update all files (#311)
  Add doctoc to CONTRIBUTING.md
  OTP auth on the client SDK and dashboard (#309)
  Revert "added filtering params"
  added filtering params
  added jwt tests again
  Disable Prettier in VSCode settings
  Remove unnecessary envvar
  TOTP retry
  Update README
  Update README
  Update README
  chore(docs): update TOC
  Add port mapping to README
  Use `pnpm run build:dev` in setup script
  SDK classes/hooks reference docs (#301)
  Contact channel client (#290)
  chore: update package versions
  fixed account settings bugs
  chore: update package versions
  ...

# Conflicts:
#	apps/backend/package.json
#	apps/dashboard/package.json
#	packages/stack/src/lib/cookie.ts
#	packages/stack/src/lib/stack-app.ts
#	pnpm-lock.yaml
  • Loading branch information
jshimko committed Oct 22, 2024
2 parents acf5b94 + 32e32d2 commit b1072aa
Show file tree
Hide file tree
Showing 287 changed files with 8,790 additions and 3,940 deletions.
Binary file modified .github/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions .github/workflows/e2e-api-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ jobs:

- name: Create .env.test.local file for examples/supabase
run: cp examples/supabase/.env.development examples/supabase/.env.test.local

- name: Create .env.test.local file for packages/stack-proxy
run: cp packages/stack-proxy/.env.development packages/stack-proxy/.env.test.local

- name: Build
run: pnpm build
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/lint-and-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ jobs:
- name: Create .env.production.local file for examples/supabase
run: cp examples/supabase/.env.development examples/supabase/.env.production.local

- name: Create .env.production.local file for packages/stack-proxy
run: cp packages/stack-proxy/.env.development packages/stack-proxy/.env.production.local

- name: Build
run: pnpm build

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/preview-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ jobs:
- name: Create .env.production.local file for examples/supabase
run: cp examples/supabase/.env.development examples/supabase/.env.production.local

- name: Create .env.production.local file for packages/stack-proxy
run: cp packages/stack-proxy/.env.development packages/stack-proxy/.env.production.local

- name: Build
run: pnpm build

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/publish-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ jobs:

- name: Create .env.production.local file for examples/supabase
run: cp examples/supabase/.env.development examples/supabase/.env.production.local

- name: Create .env.production.local file for packages/stack-proxy
run: cp packages/stack-proxy/.env.development packages/stack-proxy/.env.production.local

- name: Build
run: pnpm build
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/table-of-contents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ jobs:
- uses: technote-space/toc-generator@v4
with:
TOC_TITLE: ""
TARGET_PATHS: "README*.md,CONTRIBUTING.md"
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,10 @@
"source.organizeImports": "explicit"
}
},
"terminal.integrated.wordSeparators": " (){}',\"`─‘’“”|"
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"terminal.integrated.wordSeparators": " (){}',\"`─‘’“”|",
"editor.formatOnSave": false,
"prettier.enable": false
}
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ Welcome to Stack Auth!

Due to the nature of authentication, this may not be the easiest project to contribute to, so if you are looking for projects to help gain programming experience, we may not be a great match. If you're looking for projects for beginners, check out [Awesome First PR Opportunities](https://github.com/MunGell/awesome-for-beginners).

## Table of contents

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [How to contribute](#how-to-contribute)
- [Security & bug bounties](#security--bug-bounties)
- [Before creating a pull request](#before-creating-a-pull-request)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->


## How to contribute

If you think Stack Auth is a good fit for you, follow these steps:
Expand Down
50 changes: 35 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ We support Next.js frontends, along with any backend that can use our [REST API]
- [🏗 Development & Contribution](#-development--contribution)
- [Requirements](#requirements)
- [Setup](#setup)
- [Development environment port mapping](#development-environment-port-mapping)
- [Database migrations](#database-migrations)
- [Chat with the codebase](#chat-with-the-codebase)
- [Architecture overview](#architecture-overview)
Expand All @@ -52,6 +53,8 @@ If you answered "no" to any of these questions, then that's how Stack Auth is di

## ✨ Features

To get notified first when we add new features, please subscribe to [our newsletter](https://stack-auth.beehiiv.com/subscribe).

| | |
|-|:-:|
| <h3>`<SignIn/>` and `<SignUp/>`</h3> Authentication components that support OAuth, password credentials, and magic links, with shared development keys to make setup faster. All components support dark/light modes. | <img alt="Sign-in component" src=".github/assets/dark-light-mode.png" width="250px"> |
Expand Down Expand Up @@ -99,15 +102,15 @@ This is for you if you want to contribute to the Stack project or run the Stack

### Setup

Pre-populated .env files for the setup below are available and used by default in `.env.development` in each of the packages. You should copy all the `.env.development` files to `.env.local` in the respective packages for local development.
Pre-populated .env files for the setup below are available and used by default in `.env.development` in each of the packages. (Note: If you're creating a production build (eg. with `pnpm run build`), you must supply the environment variables manually.)

In a new terminal:

```sh
pnpm install

# Run build to build everything once
pnpm run build
pnpm run build:dev

# reset & start the dependencies (DB, Inbucket, etc.) as Docker containers, seeding the DB with the Prisma schema
pnpm run start-deps
Expand All @@ -121,7 +124,7 @@ pnpm run dev
pnpm run test
```

You can now open the dashboard at [http://localhost:8101](http://localhost:8101), API on port 8102, demo on port 8103, docs on port 8104, Inbucket (e-mails) on port 8105, and Prisma Studio on port 8106.
You can now open the dashboard at [http://localhost:8101](http://localhost:8101), API on port 8102, demo on port 8103, docs on port 8104, Inbucket (e-mails) on port 8105, and Prisma Studio on port 8106. See the section below on more information on the ports of the running services.

Your IDE may show an error on all `@stackframe/XYZ` imports. To fix this, simply restart the TypeScript language server; for example, in VSCode you can open the command palette (Ctrl+Shift+P) and run `Developer: Reload Window` or `TypeScript: Restart TS server`.

Expand All @@ -131,6 +134,25 @@ You can also open Prisma Studio to see the database interface and edit data dire
pnpm run prisma studio
```

### Development environment port mapping

8101. Dashboard (equivalent to https://app.stack-auth.com)
8102. Backend (equivalent to https://api.stack-auth.com)
8103. Demo app (equivalent to https://demo.stack-auth.com)
8104. Docs (equivalent to https://docs.stack-auth.com)
8105. Inbucket (e-mails)
8106. Prisma Studio
8107. Jaeger UI/OpenTelemetry (for performance tracing)
8108. `examples/docs-examples`
8109. `examples/partial-prerendering`
8110. `examples/cjs-test`
8111. `examples/e-commerce`
8112. `examples/middleware`
8113. Svix server (for webhooks)
8114. OAuth mock server
8115. `examples/supabase`


### Database migrations

If you make changes to the Prisma schema, you need to run the following command to create a migration:
Expand All @@ -151,16 +173,16 @@ Storia trained an [AI on our codebase](https://sage.storia.ai/stack-auth) that c
User((User))
Admin((Admin))
subgraph "Stack Auth System"
Dashboard[Stack Dashboard<br/>Next.js]
Backend[Stack API Backend<br/>Next.js]
Dashboard[Stack Dashboard<br/>/apps/dashboard]
Backend[Stack API Backend<br/>/apps/backend]
Database[(PostgreSQL Database)]
EmailService[Email Service<br/>Inbucket]
WebhookService[Webhook Service<br/>Svix]
subgraph "Shared Packages"
StackSDK[Stack<br/>Client SDK]
StackUI[Stack UI<br/>React Components]
StackShared[Stack Shared<br/>Utilities]
StackEmails[Stack Emails<br/>Email Templates]
StackSDK[Client SDK<br/>/packages/stack]
subgraph Shared
StackUI[Stack UI<br/>/packages/stack-ui]
StackShared[Stack Shared<br/>/packages/stack-shared]
StackEmails[Stack Emails<br/>/packages/stack-emails]
end
end
Admin --> Dashboard
Expand All @@ -169,13 +191,11 @@ Storia trained an [AI on our codebase](https://sage.storia.ai/stack-auth) that c
Backend --> Database
Backend --> EmailService
Backend --> WebhookService
Dashboard --> StackUI
Dashboard --> StackShared
Dashboard --> StackEmails
Dashboard --> Shared
Dashboard --> StackSDK
StackSDK --HTTP Requests--> Backend
Backend --> StackShared
Backend --> StackEmails
StackSDK --> Shared
Backend --> Shared
classDef container fill:#1168bd,stroke:#0b4884,color:#ffffff
classDef database fill:#2b78e4,stroke:#1a4d91,color:#ffffff
classDef external fill:#999999,stroke:#666666,color:#ffffff
Expand Down
71 changes: 71 additions & 0 deletions apps/backend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,76 @@
# @stackframe/stack-backend

## 2.6.11

### Patch Changes

- fixed account settings bugs
- Updated dependencies
- @stackframe/stack-emails@2.6.11
- @stackframe/stack-shared@2.6.11

## 2.6.10

### Patch Changes

- Various bugfixes
- Updated dependencies
- @stackframe/stack-emails@2.6.10
- @stackframe/stack-shared@2.6.10

## 2.6.9

### Patch Changes

- - New contact channel API
- Fixed some visual gitches and typos
- Bug fixes
- Updated dependencies
- @stackframe/stack-emails@2.6.9
- @stackframe/stack-shared@2.6.9

## 2.6.8

### Patch Changes

- Bugfixes
- Updated dependencies
- @stackframe/stack-shared@2.6.8
- @stackframe/stack-emails@2.6.8

## 2.6.7

### Patch Changes

- Bugfixes
- @stackframe/stack-shared@2.6.7
- @stackframe/stack-emails@2.6.7

## 2.6.6

### Patch Changes

- @stackframe/stack-emails@2.6.6
- @stackframe/stack-shared@2.6.6

## 2.6.5

### Patch Changes

- Minor improvements
- Updated dependencies
- @stackframe/stack-emails@2.6.5
- @stackframe/stack-shared@2.6.5

## 2.6.4

### Patch Changes

- fixed small problems
- Updated dependencies
- @stackframe/stack-emails@2.6.4
- @stackframe/stack-shared@2.6.4

## 2.6.3

### Patch Changes
Expand Down
6 changes: 1 addition & 5 deletions apps/backend/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,4 @@ const nextConfig = {
},
};

export default withConfiguredSentryConfig(
withBundleAnalyzer(
nextConfig
)
);
export default withConfiguredSentryConfig(withBundleAnalyzer(nextConfig));
5 changes: 3 additions & 2 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stackframe/stack-backend",
"version": "2.6.3",
"version": "2.6.11",
"private": true,
"scripts": {
"clean": "rimraf .next && rimraf node_modules",
Expand Down Expand Up @@ -48,11 +48,12 @@
"@stackframe/stack-emails": "workspace:*",
"@stackframe/stack-shared": "workspace:*",
"@vercel/analytics": "^1.2.2",
"@vercel/functions": "^1.4.2",
"@vercel/otel": "^1.10.0",
"bcrypt": "^5.1.1",
"dotenv-cli": "^7.3.0",
"jose": "^5.2.2",
"next": "^14.1",
"next": "^14.2.5",
"next-runtime-env": "^3.2.2",
"nodemailer": "^6.9.10",
"openid-client": "^5.6.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- DropIndex
DROP INDEX "StandardOAuthProviderConfig_projectConfigId_clientId_key";
2 changes: 0 additions & 2 deletions apps/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,6 @@ model StandardOAuthProviderConfig {
// each type of standard OAuth provider can only be used once per project
@@id([projectConfigId, id])
// each client id can only be used once per project
@@unique([projectConfigId, clientId])
}

model AuthMethod {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { usersCrudHandlers } from "@/app/api/v1/users/crud";
import { getAuthContactChannel } from "@/lib/contact-channel";
import { getProject } from "@/lib/projects";
import { validateRedirectUrl } from "@/lib/redirect-urls";
import { oauthCookieSchema } from "@/lib/tokens";
Expand All @@ -9,7 +10,7 @@ import { InvalidClientError, Request as OAuthRequest, Response as OAuthResponse
import { KnownError, KnownErrors } from "@stackframe/stack-shared";
import { ProjectsCrud } from "@stackframe/stack-shared/dist/interface/crud/projects";
import { yupMixed, yupNumber, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields";
import { StackAssertionError, StatusError, captureError, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
import { StackAssertionError, StatusError } from "@stackframe/stack-shared/dist/utils/errors";
import { extractScopes } from "@stackframe/stack-shared/dist/utils/strings";
import { cookies } from "next/headers";
import { redirect } from "next/navigation";
Expand Down Expand Up @@ -268,14 +269,32 @@ const handler = createSmartRouteHandler({
if (!project.config.sign_up_enabled) {
throw new KnownErrors.SignUpNotEnabled();
}

let primaryEmailAuthEnabled = true;
if (userInfo.email) {
const oldContactChannel = await getAuthContactChannel(
prismaClient,
{
projectId: outerInfo.projectId,
type: 'EMAIL',
value: userInfo.email,
}
);

if (oldContactChannel && oldContactChannel.usedForAuth) {
primaryEmailAuthEnabled = false;
}
// TODO: check whether this OAuth account can be used to login to another existing account instead
}

const newAccount = await usersCrudHandlers.adminCreate({
project,
data: {
display_name: userInfo.displayName,
profile_image_url: userInfo.profileImageUrl || undefined,
primary_email: userInfo.email,
primary_email_verified: userInfo.emailVerified,
primary_email_auth_enabled: false,
primary_email_auth_enabled: primaryEmailAuthEnabled,
oauth_providers: [{
id: provider.id,
account_id: userInfo.accountId,
Expand Down Expand Up @@ -315,4 +334,4 @@ const handler = createSmartRouteHandler({
});

export const GET = handler;
export const POST = handler;
export const POST = handler;
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ export const POST = createSmartRouteHandler({
body: await response.json()
};
}
});
});
Loading

0 comments on commit b1072aa

Please sign in to comment.