Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update self hosted init #4264

Merged
merged 26 commits into from
Oct 19, 2023

Conversation

logan-anderson
Copy link
Contributor

@logan-anderson logan-anderson commented Oct 17, 2023

Update ready for testing but here are some known issues

  • Typescript errors in database.ts and config.ts
  • the path to the database client in the generated database file may be wrong if the user is using src
  • It currently asks to overwrite config file when doing backend config. It should probably just log out changes and never overwrite

Video explanation: https://www.loom.com/share/de8caec647704e5a905aaf6ae6ba1498?sid=b9792d50-cc3a-4421-b712-a818f2470427

@changeset-bot
Copy link

changeset-bot bot commented Oct 17, 2023

⚠️ No Changeset found

Latest commit: eacdbf2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@logan-anderson logan-anderson added the tagged This PR should be given a tagged release label Oct 17, 2023
@kldavis4
Copy link
Member

Ran into this error when running init backend:

➜  empty git:(feat/self-hosted-init) ✗ pnpm run init-dev-backend

> starter-empty@ init-dev-backend /Users/kldavis/projects/tinacms/examples/empty
> tinacms init backend

✔ What framework are you using? › Next.js
✔ Choose your package manager › PNPM
✔ Do you want to use Tina Cloud to host your backend or self-host? (In self hosting you will have to bring your own auth, database and backend) › Tina Cloud
✔ What is your Tina Cloud Client ID? (Hit enter to skip and set up yourself later)
Don't have a Client ID? Create one here: https://app.tina.io/projects/new … kjsfdlkjf
✔ What is your Tina Cloud Read Only Token?
Don't have a Read Only Token? Create one here: https://app.tina.io/projects/kjsfdlkjf/tokens … kldsjfkldj
✔ Found existing file at tina/config.ts. Would you like to overwrite? … yes
Adding dev dependencies, this might take a moment...
  ┃ pnpm add -D @types/node
Error occured during tinacms init
TypeError: Cannot read properties of undefined (reading 'name')
    at apply (/Users/kldavis/projects/tinacms/packages/@tinacms/cli/dist/index.js:5394:69)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async CLICommand.execute (/Users/kldavis/projects/tinacms/packages/@tinacms/cli/dist/index.js:4037:5)
    at async InitCommand.execute (/Users/kldavis/projects/tinacms/packages/@tinacms/cli/dist/index.js:5823:5)
    at async InitCommand.validateAndExecute (/Users/kldavis/projects/tinacms/node_modules/.pnpm/clipanion@3.2.0_typanion@3.13.0/node_modules/clipanion/lib/advanced/Command.js:73:26)
    at async Cli.run (/Users/kldavis/projects/tinacms/node_modules/.pnpm/clipanion@3.2.0_typanion@3.13.0/node_modules/clipanion/lib/advanced/Cli.js:223:24)
    at async Cli.runExit (/Users/kldavis/projects/tinacms/node_modules/.pnpm/clipanion@3.2.0_typanion@3.13.0/node_modules/clipanion/lib/advanced/Cli.js:232:28)
 ELIFECYCLE  Command failed with exit code 1.

@logan-anderson
Copy link
Contributor Author

@kldavis4 "TypeError: Cannot read properties of undefined (reading 'name')" has been fixed. Good catch

@logan-anderson logan-anderson marked this pull request as ready for review October 19, 2023 12:50
@logan-anderson logan-anderson requested a review from a team as a code owner October 19, 2023 12:50
@logan-anderson logan-anderson merged commit 147eb61 into feat/self-hosted-improvements Oct 19, 2023
4 of 5 checks passed
@logan-anderson logan-anderson deleted the feat/self-hosted-init branch October 19, 2023 14:30
coreyaus pushed a commit to coreyaus/tinacms that referenced this pull request Nov 17, 2023
* improvements to Self Hosted Tina.  (tinacms#4095)

* inital improvments in self hosted

* update database files

* use createDatabaseInternal

* fix type build

* added changeset

* use databaseClient

* add file system bridge to createLocalDatabase

* Update .changeset/great-seahorses-yell.md

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update .changeset/great-seahorses-yell.md

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update .changeset/great-seahorses-yell.md

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update .changeset/great-seahorses-yell.md

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update examples/tina-self-hosted-demo/pages/[filename].tsx

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* update backendClient to databaseClient

* fix typo

* move gitProvider interface to graphql package

* add files

* add more options to GithubProvider

* Update types

* update changeset

* update changeset

* move github provider to its own package

* rename tinacms-provider-github to tinacms-gitprovider-github

* Update packages/tinacms-gitprovider-github/README.md

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/tinacms-gitprovider-github/README.md

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

---------

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* feat: tinacms-next-auth + feat: self-hosted cli improvements (tinacms#4105)

* feat: next-auth-tinacms package

* update lockfile

* fix build

* change entrypoint to node and update typescript

* downgrade typescript and next

* update lock file

* pin deps

* remove @types/node

* add bin

* add bin wrapper

* switch to clipanion and fix deps that were breaking executable

* add isomorphic-fetch

* create function for generating nextauth auth handler

* change target

* try not targeting node

* revert target change

* split out frontend code

* add missing await

* feat: add self-hosted init w/ refactoring of existing init

* consistently use await

* has -> exists; add gitignore checks to environment

* refactor templates. Add next-auth-tinacms dependency

* implement custom auth in config templates

* generate auth.ts

* add missing import for next auth

* refactor generated files and add generated command handler interface

* refactor files to match handler interface

* generate nextauth api handler and further refactoring of generated files

* implement register api handler generation

* ensure generated file parent directory exists

* generate database.ts

* remove unused

* fix logic to disable clientId, token questions

* add missing changeset

* misc bug fixes

* generate .env and use it to save settings

* rename next-auth integration

* rename next-auth integration

* generate gql endpoint

* add github personal access token to config

* fix name of client id

* update lock file

* initial version update

* fix name of package in changeset

* fix references to next-auth-tinacms

* drop inquirer for auth cli in favor of prompts for consistency

* update lock file

* fix choice access

* initialize tailwind and fix issue with contentApiUrlOverride not getting set

* add missing comma

* don't write global.css

* fix logo generation; add debug params

* add isLocal environment variable to dev script

* fix prompt for nextauth provider

* fix nextjs style resolution to handle '@'

* add debug; fix path replace

* override -> overwrite

* try fixing path computation again

* remove debug

* make file output consistent

* remove tailwind from regular deps

* update database template to use new gitprovider stuff

* update extendNextScripts to allow it to be run repeatedly

* fix auth reference

* fix to not redefine req.session

* fix client request

* add .env to gitignore

* add ts-nocheck to ignore type errors in generated files

* add defaults to fix type issues

* try fix for `Could not find a declaration file for module '@tinacms/datalayer'`

* add types to exports

* add ts-nocheck to generated database client

* refactor next templates; set correct client in generated post page dependent on whether data layer is enabled

* quotes -> backticks

* give meaningful names to generic types

* pr feedback

* pr feedback

* detect next app dir and display error message if present

* add short blurb to readme

* use css modules to avoid adding / modifying tailwind

* attempt to use tag version for dependencies

* add cli version to environment

* try dynamic require

* parse version from command line args

* debugging

* make tinaVersion a cli argument

* fix name of modules

* fix generated css

* add setup users script if kv provider enabled

* Fix/base init (tinacms#4114)

* remove question about env var names

* add more context to final log message

* update

* update

* update main in package.json

* make branch consistent

* update to use correct comment in css module

* fix script

* better error handling

* update styles

* and backend commit sub command

* only add files in normal init or when the config is not present

* remove unused code

* generate the js code for the js client

* only install deps if there are any

* only set NEXTAUTH_CREDENTIALS_KEY in backend init

* added changeset

* ask to override files when doing backend init and self hosting

* log out code sample of config update

* fix typo

* feat: ENG-1119: validate KV env vars

* move code snipped to end

* install next-tinacms-auth when the user enables it

* fix typo and call function

* Fix hasSelfHostedConfig calls which are a function instead of a property (tinacms#4148)

* return apiUrl Correctly

* Update packages/@tinacms/cli/src/cmds/init/apply.ts

Co-authored-by: James O'Halloran <james.p.ohalloran@gmail.com>

* Only write self hosted Env when self hosting

* update logs at the end of init

* update link

* Update packages/@tinacms/cli/src/cmds/init/configure.ts

* update text on backend init questions

* remove typescript from generated files

* fix issue where deps would not getting installed

* Fix issues caused by the prompts being skipped when there's an existin config file

* Add typescript property to api/gql endpoint generator

* Make NEXTAUTH_CREDENTIALS_KEY optional (tinacms#4158)

* feat: ENG-1116: stop generating .env.tina

* fix typo

* fix: missing call to request

* fix: typo

* Always ask for pacakge manager (tinacms#4162)

* always ask for package manager

* code cleanup

* use package.json to see if tina deps are installed

* fix adduser

* Wrap up auth provider

* rework to NextAuthProvider

* use auth provider

* add clerk provider package

* use authHooks

* fix tests

* added changeset

* fix: make the reactive example a GeneratedFile and prompt for overwrite during backend init

* fix: type addReactiveFile function

* Update index.tsx

* typo

* use src/pages instead of src when doing init (tinacms#4203)

* Remove start script (tinacms#4207)

* remove start script from extendNextScripts

* update tests

* feat: Tina nextauth integration (tinacms#4205)

* feat: tina nextauth integration

* fix: remove cli entrypoint

* feat: improve styling of login form

* make authHooks optional

* feat: switch to per collection isAuthCollection attribute

* refactor: determine password field using field type

* fix: getToken return types

* fix: bad import

* feat: implement password form plugin

* fix: set autoComplete off to hint to browser not to save the password

* fix: remove cruft

* fix: make name different than username

* chore: update tina-lock

* fix: check only for user object to determine if authenticated

* feat: add support for updatePassword mutation

* feat: UI for updating password

* fix: self-hosted react app issues (following next & react upgrade)

* fix: icon for password change

* fix: styling of login

* fix: clear dirty flag after update succeeds

* add bcryptjs to package.json (tinacms#4208)

* Remove ts-expect-errors (tinacms#4209)

* add bcryptjs to package.json

* remove ts-expect-errors

* fix: async unmount issue when logging in

* fix: react controlled input bug

* fix: unmounting logic

* feat: overhaul to use single doc collections for auth

* feat: make auth provider params fully optional

* fix: add null check for when a password field doesn't exist

* fix: update snapshot

* fix: provide defaults for password / id fields

* fix: collection not getting passed to _indexContent

* fix: explicitly set local auth provider

* refactor: tinacms-next-auth -> tinacms-authjs

* refactor: isIdentifier -> uid

* feat: provide a default user collection

* fix: remove unnecessary await

* update lodash imports (tinacms#4217)

* fix: null-safe authorize

* fix: add checks in auth to verify id field and password field exist

* fix: null-safe role check (take 2)

* fix: hide password update in local mode

* fix: double encoding on password change

* fix: broken account menu logic

* fix tests

* fix: get error message from nextauth and display to user

* fix: authenticate / authorize to not throw gql exception when normal auth failure occurs

* feat: add namespace property to database to allow content to be namespaced by branch

* make boilerplate easier to generate (tinacms#4221)

* make boilerplate easier to generate

* fix: authorization should check authorize is defined

* fix: call authorize not request

* fix: only require password field when authenticating

* fix: add prop to specify the field on the jwt to use as uid

* fix: add debug option and pass uid prop to session

* fix: access authorize correctly

---------

Co-authored-by: Logan Anderson <43075109+logan-anderson@users.noreply.github.com>
Co-authored-by: Logan Anderson <landerson2@upei.ca>

* feat: custom next-auth api endpoint path (tinacms#4233)

* fix: wrong package directory

* feat: support custom next-auth path (`/api/tina/auth/*`) to support consolidated api without rewrite

* add node backend functions (tinacms#4231)

* allow tinacms to be used in a single backend function

* add changset

* use older next version

* use node APIs instead of nextjs

* remove console log

* use req and res of handler

* update self-hosted example

* Remove auth.js file

* add local authentication

* check user role

* fix deps of tinacms-authjs

* Rename isAuthenticated to isAuthorized and use  proper status codes

* update naming to be consistent

* remove unused exports from tinacms-authjs

* rename isAuthRequired to secure

* move node.ts to backend/index.ts

* export directly from datalayer package

* fix: return promise from nextauth handler

* fix: await instead of return

* feat: warn nextauth custom provider (tinacms#4248)

* feat: add warning when not using tina credentials provider with self-hosted backend

* add WARNING prefix

* Update self hosted init (tinacms#4264)

* move prompts to typesafe helper functions

* reorganize code to be fully typesafe

* remove unused file

* remove self hosted init command

* update apply to write to [...routes] and use new database format

* fix tinacms init issues

* fix typos in generated files

* fix typo in generated db file

* use correct path for generated next api route

* better organization of prompt code

* remove unused code

* ask about generated files

* only add example on first time setup

* install cli as a dev dep

* log env vars

* only add example on first time init

* fix tina cloud auth example

* fix generated config and install

* format config file

* add databaseAdapter imports to database file

* fix error 'can not read properity name of undefined'

* take into account using src dir when making the next api route

* only ask to overwrite config file if we are not doing backend init

* remove duplicated logic for tina cloud setup

* update types

* fix session provider types

* fix: frontMatterFormat detection and type

* install datalayer package when self hosting

* make sure next-auth is installed when using authJs provider

* remove tina cloud from list of auth providers

* Add user collection to init (tinacms#4277)

* do not ask for auth provider

* add user collection to init process

* add secure: true to gql endpoint (tinacms#4280)

* feat: cli init update tina config (tinacms#4284)

* feat: update cli backend init to update tina config instead of requiring manual update

* update comment for visitor function

* fix: comment out custom options for git provider and database adapter

* fix: revert lockfile

* fix: type error

* update config codegen to use some of the config options instead of hard coding

* add users/index.json file when doing init (tinacms#4287)

* add users/index.json file when doing init

* Update packages/@tinacms/cli/src/cmds/init/apply.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

---------

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Fix clerk auth (tinacms#4286)

* fix clerk auth to use the new auth pattern

* update authorize and get user function

* auth provider should be the users auth provider if provided (tinacms#4298)

* fix: override name property on CredentialsProvider so warning message isn't erroneously shown (tinacms#4302)

* fix clerk auth and add orgId (tinacms#4296)

* fix clerk auth and add orgId

* update

* Update packages/tinacms-clerk/src/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/tinacms-clerk/src/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/tinacms-clerk/src/tinacms.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

---------

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* refactor: authentication -> authProvider (tinacms#4291)

* feat: prompt user for password change (tinacms#4299)

* feat: prompt user for password change

* fix: password form validation

* fix: preserve existing password

* fix: update tina lock

* fix: type error

* fix: static media

* fix: errors can not be undefined (tinacms#4309)

* fix: add @tinacms/auth to changeset

* fix: typo

* Backend improvements (tinacms#4306)

* add backend improvments

* Update packages/@tinacms/datalayer/src/backend/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/@tinacms/datalayer/src/backend/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/@tinacms/datalayer/src/backend/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/@tinacms/datalayer/src/backend/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/@tinacms/datalayer/src/backend/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/@tinacms/datalayer/src/backend/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/tinacms-authjs/src/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/@tinacms/datalayer/src/backend/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/tinacms-authjs/src/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/tinacms-authjs/src/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/tinacms-authjs/src/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/tinacms-authjs/src/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/@tinacms/datalayer/src/backend/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/@tinacms/datalayer/src/backend/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/@tinacms/datalayer/src/backend/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* Update packages/@tinacms/datalayer/src/backend/index.ts

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

---------

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* fix: add a default content namespace when one is not specified

* fix: typo

* fix generated users/index.json file (tinacms#4314)

* fix: apply namespace to metadata

* fix self hosted types (tinacms#4315)

* fix self hosted types

* update types

* update types

* export client from generated databse client (tinacms#4316)

* fix: no redirect on logout & update mongodb-level (tinacms#4319)

* fix: call onLogout & redirect only after logout returns

* chore: update mongodb-level

* fix logout() return type in DefaultAuthJSProvider

* fix add async

* Minor Improvements (tinacms#4324)

* add small imporovments

* create .env file if it does not exsist

* add message about usnig the backend client

* update message

* typo

* feat: move users collection to site section and change icon to users (tinacms#4323)

* fix issues with generated config file (tinacms#4325)

* fix issues with generated files (tinacms#4331)

* update to use new version of upstash-redis-level (tinacms#4339)

* consolidate all changesets into a single changeset (tinacms#4340)

* Update examples/tina-self-hosted-demo/tina/config.tsx

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>

* fix: namespace is now an optional argument to createDatabase (tinacms#4344)

* fix: deprecated build.auth -> authProvider

---------

Co-authored-by: Kelly Davis <kldavis4@users.noreply.github.com>
Co-authored-by: Kelly Davis <kelly.davis@forestry.io>
Co-authored-by: Jeff See <jeffsee.55@gmail.com>
Co-authored-by: James O'Halloran <james.p.ohalloran@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tagged This PR should be given a tagged release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants