Skip to content

Commit

Permalink
feat: self-hosting improvements (#4310)
Browse files Browse the repository at this point in the history
* improvements to Self Hosted Tina.  (#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 (#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 (#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 (#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 (#4158)

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

* fix typo

* fix: missing call to request

* fix: typo

* Always ask for pacakge manager (#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 (#4203)

* Remove start script (#4207)

* remove start script from extendNextScripts

* update tests

* feat: Tina nextauth integration (#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 (#4208)

* Remove ts-expect-errors (#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 (#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 (#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 (#4233)

* fix: wrong package directory

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

* add node backend functions (#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 (#4248)

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

* add WARNING prefix

* Update self hosted init (#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 (#4277)

* do not ask for auth provider

* add user collection to init process

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

* feat: cli init update tina config (#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 (#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 (#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 (#4298)

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

* fix clerk auth and add orgId (#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 (#4291)

* feat: prompt user for password change (#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 (#4309)

* fix: add @tinacms/auth to changeset

* fix: typo

* Backend improvements (#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 (#4314)

* fix: apply namespace to metadata

* fix self hosted types (#4315)

* fix self hosted types

* update types

* update types

* export client from generated databse client (#4316)

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

* fix: call onLogout & redirect only after logout returns

* chore: update mongodb-level

* fix logout() return type in DefaultAuthJSProvider

* fix add async

* Minor Improvements (#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 (#4323)

* fix issues with generated config file (#4325)

* fix issues with generated files (#4331)

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

* consolidate all changesets into a single changeset (#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 (#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>
  • Loading branch information
5 people authored Nov 17, 2023
1 parent 251a954 commit a65ca13
Show file tree
Hide file tree
Showing 128 changed files with 8,524 additions and 2,661 deletions.
214 changes: 214 additions & 0 deletions .changeset/calm-fireants-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
---
'tinacms-gitprovider-github': major
'tinacms-authjs': major
'tinacms-clerk': major
'@tinacms/starter': patch
'next-tinacms-cloudinary': patch
'@tinacms/self-hosted-starter': patch
'@tinacms/schema-tools': patch
'@tinacms/datalayer': patch
'@tinacms/graphql': patch
'@tinacms/scripts': patch
'next-tinacms-dos': patch
'next-tinacms-s3': patch
'@tinacms/auth': patch
'e2e-next': patch
'@tinacms/cli': patch
'@tinacms/mdx': patch
'tinacms': patch
---

## TinaCMS Self hosted Updates

### Changes in the database file

#### Deprecations and Additions

- **Deprecated**: `onPut`, `onDelete`, and `level` arguments in `createDatabase`.
- **Added**: `databaseAdapter` to replace `level`.
- **Added**: `gitProvider` to substitute `onPut` and `onDelete`.
- **New Package**: `tinacms-gitprovider-github`, exporting the `GitHubProvider` class.
- **Interface Addition**: `gitProvider` added to `@tinacms/graphql`.
- **Addition**: Generated database client.

#### Updated `database.ts` Example
```typescript
import { createDatabase, createLocalDatabase } from '@tinacms/datalayer'
import { MongodbLevel } from 'mongodb-level'
import { GitHubProvider } from 'tinacms-gitprovider-github'

const isLocal = process.env.TINA_PUBLIC_IS_LOCAL === 'true'

export default isLocal
? createLocalDatabase()
: createDatabase({
gitProvider: new GitHubProvider({
branch: process.env.GITHUB_BRANCH,
owner: process.env.GITHUB_OWNER,
repo: process.env.GITHUB_REPO,
token: process.env.GITHUB_PERSONAL_ACCESS_TOKEN,
}),
databaseAdapter: new MongodbLevel<string, Record<string, any>>({
collectionName: 'tinacms',
dbName: 'tinacms',
mongoUri: process.env.MONGODB_URI,
}),
namespace: process.env.GITHUB_BRANCH,
})

```

### Migrating `database.ts`

#### a. Replacing `onPut` and `onDelete` with `gitProvider`

- **GitHubProvider Usage**: Replace `onPut` and `onDelete` with `gitProvider`, using the provided `GitHubProvider` for GitHub.

```typescript
const gitProvider = new GitHubProvider({
branch: process.env.GITHUB_BRANCH,
owner: process.env.GITHUB_OWNER,
repo: process.env.GITHUB_REPO,
token: process.env.GITHUB_PERSONAL_ACCESS_TOKEN,
});
```
- **Custom Git Provider**: Implement the `GitProvider` interface for different git providers.

If you are not using Github as your git provider, you can implement the `GitProvider` interface to use your own git provider.

```typescript
class CustomGitProvider implements GitProvider
async onPut(key: string, value: string)
// ...

async onDelete(key: string)
// ...


const gitProvider = new CustomGitProvider();
```
#### b. Renaming `level` to `databaseAdapter`
- **Renaming in Code**: Change `level` to `databaseAdapter` for clarity.
```diff
createDatabase({
- level: new MongodbLevel<string, Record<string, any>>(...),
+ databaseAdapter: new MongodbLevel<string, Record<string, any>>(...),
})
```
#### c. `createLocalDatabase` Function
- **Usage**: Implement a local database with the `createLocalDatabase` function.
```typescript
import { createLocalDatabase } from '@tinacms/datalayer';
createLocalDatabase(port);
```

#### d. Consolidated Example
- **Updated `database.{ts,js}` File**:

```typescript
import { createDatabase, createLocalDatabase, GitHubProvider } from '@tinacms/datalayer';
import { MongodbLevel } from 'mongodb-level';
const isLocal = process.env.TINA_PUBLIC_IS_LOCAL === 'true';
export default isLocal
? createLocalDatabase()
: createDatabase({
gitProvider: new GitHubProvider(...),
databaseAdapter: new MongodbLevel<string, Record<string, any>>(...),
});
```


### Summary of Authentication Updates in Config

#### a. AuthProvider and AbstractAuthProvider
- **New**: `authProvider` in `defineConfig`.
- **Class**: `AbstractAuthProvider` for extending new auth providers.
- **Clerk Auth Provider**: New provider added.
- **Renaming**: `admin.auth` to `admin.authHooks`.
- **Deprecation**: `admin.auth`.

#### b. Auth Provider in Internal Client and Config
- **Transition**: From auth functions to `authProvider` class.

#### c. Migration for Authentication
- **Previous API**:

```javascript
defineConfig({
admin: {
auth: {
login() {},
logout() {},
//...
}
}
//...
})
```
- **New API**:

```javascript
import { AbstractAuthProvider } from 'tinacms';
class CustomAuthProvider extends AbstractAuthProvider {
login() {}
logout() {}
//...
}
defineConfig({
authProvider: new CustomAuthProvider()
//...
})
```


### TinaCMS Self Hosted backend updates

- **New:** TinaNodeBackend is exported from `@tinacms/datalayer`. This is used to host the TinaCMS backend in a single function.
- **New:** `LocalBackendAuthProvider` is exported from `@tinacms/datalayer`. This is used to host the TinaCMS backend locally.

- **New:** `AuthJsBackendAuthProvider` is exported from `tinacms-authjs`. This is used to host the TinaCMS backend with AuthJS.

### Migrating the TinaCMS backend

Now, instead of hosting the in /tina/api/gql.ts file, the entire TinaCMS backend (including auth) will be hosted in a single backend function.

`/api/tina/[...routes].{ts,js}`

```typescript
import { TinaNodeBackend, LocalBackendAuthProvider } from '@tinacms/datalayer'

import { TinaAuthJSOptions, AuthJsBackendAuthProvider } from 'tinacms-authjs'

import databaseClient from '../../../tina/__generated__/databaseClient'

const isLocal = process.env.TINA_PUBLIC_IS_LOCAL === 'true'

const handler = TinaNodeBackend({
authProvider: isLocal
? LocalBackendAuthProvider()
: AuthJsBackendAuthProvider({
authOptions: TinaAuthJSOptions({
databaseClient: databaseClient,
secret: process.env.NEXTAUTH_SECRET,
}),
}),
databaseClient,
})

export default (req, res) => {
// Modify the request here if you need to
return handler(req, res)
}
```


These changes are put in place to make self hosted TinaCMS easier to use and more flexible.


Please [check out the docs](https://tina.io/docs/self-hosted/overview) for more information on self hosted TinaCMS.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ dist/**
.next/**


# Ignore all .env files
**/**/.env
# All .env files
**/.env
**/.env
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ Test a TinaCMS starter site locally
npx create-tina-app@latest
```

Or try a [demo site](https://app.tina.io/quickstart) on Tina Cloud

Or try a [demo site](https://app.tina.io/quickstart) on Tina Cloud

## Documentation

Expand All @@ -53,12 +52,11 @@ Please see our [./CONTRIBUTING.md](https://github.com/tinacms/tinacms/blob/main/

### Maintainers

- Jeff See ([@jeffsee55](https://github.com/jeffsee55))
- James O'Halloran ([@jamespohalloran](https://github.com/jamespohalloran))
- Logan Anderson ([@logan_anders0n](https://twitter.com/logan_anders0n))
- Jeff See ([@jeffsee55](https://github.com/jeffsee55))
- James O'Halloran ([@jamespohalloran](https://github.com/jamespohalloran))
- Logan Anderson ([@logan_anders0n](https://twitter.com/logan_anders0n))
- Kelly Davis ([@kldavis](https://github.com/kldavis4))


### All Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-iframe/tina/tina-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/kitchen-sink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@tinacms/datalayer": "workspace:*",
"graphql": "^15.1.0",
"jest-file-snapshot": "^0.5.0",
"mongodb-level": "^0.0.2",
"mongodb-level": "^0.0.3",
"next": "12.2.4",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
37 changes: 17 additions & 20 deletions examples/kitchen-sink/tina/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,24 @@ const router = ({ document, collection }) => {
const extendedRouter = ({ document, collection }) => {
return `/${collection.name}/${document._sys.breadcrumbs.join('/')}`
}

const customAuthProvider = {
getToken: async () => {
return { id_token: 'some-token' }
},
logout: async () => {
localStorage.removeItem(TINA_TOKEN_KEY)
},
authenticate: async () => {
localStorage.setItem(TINA_TOKEN_KEY, 'some-token')
return true
},
getUser: async () => {
return localStorage.getItem(TINA_TOKEN_KEY)
},
}
export default defineConfig({
// contentApiUrlOverride: '/api/gql',
admin: {
auth: {
useLocalAuth: true,
// If you wanted to use custom auth
customAuth: true,
getToken: async () => {
return { id_token: 'some-token' }
},
logout: async () => {
localStorage.removeItem(TINA_TOKEN_KEY)
},
authenticate: async () => {
localStorage.setItem(TINA_TOKEN_KEY, 'some-token')
return true
},
getUser: async () => {
return localStorage.getItem(TINA_TOKEN_KEY)
},
},
},
build: {
outputFolder: 'admin',
publicFolder: 'public',
Expand All @@ -56,6 +52,7 @@ export default defineConfig({
branch: null,
clientId: null,
token: null,
authProvider: customAuthProvider,
schema: {
collections: [
{
Expand Down
9 changes: 2 additions & 7 deletions examples/kitchen-sink/tina/database.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { createDatabase, TinaLevelClient } from '@tinacms/datalayer'
import { createLocalDatabase } from '@tinacms/datalayer'

const localLevelStore = new TinaLevelClient()
localLevelStore.openConnection()

export default createDatabase({
level: localLevelStore,
})
export default createLocalDatabase()
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const Footer = ({ data, icon, rawData }) => {
<footer className={`bg-gradient-to-br ${footerColorCss}`}>
<Container className="relative" size="small">
<div className="flex justify-between items-center gap-6 flex-wrap">
<Link href="/" passHref>
<Link legacyBehavior href="/" passHref>
<a className="group mx-2 flex items-center font-bold tracking-tight text-gray-400 dark:text-gray-300 opacity-50 hover:opacity-100 transition duration-150 ease-out whitespace-nowrap">
<Icon
parentColor={data.color}
Expand Down
8 changes: 6 additions & 2 deletions examples/tina-self-hosted-demo/components/layout/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const Header = ({ data }) => {
<Container size="custom" className="py-0 relative z-10 max-w-8xl">
<div className="flex items-center justify-between gap-6">
<h4 className="select-none text-lg font-bold tracking-tight my-4 transition duration-150 ease-out transform">
<Link href="/" passHref>
<Link legacyBehavior href="/" passHref>
<a className="flex gap-1 items-center whitespace-nowrap tracking-[.002em]">
<Icon
parentColor={data.color}
Expand Down Expand Up @@ -99,7 +99,11 @@ export const Header = ({ data }) => {
activeItem ? activeItemClasses[theme.color] : ''
}`}
>
<Link href={`${prefix}/${item.href}`} passHref>
<Link
legacyBehavior
href={`${prefix}/${item.href}`}
passHref
>
<a
className={`relative select-none text-base inline-block tracking-wide transition duration-150 ease-out hover:opacity-100 py-8 px-4 ${
activeItem ? `` : `opacity-70`
Expand Down
1 change: 1 addition & 0 deletions examples/tina-self-hosted-demo/components/posts/posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const Posts = ({ data }) => {
}
return (
<Link
legacyBehavior
key={post._sys.filename}
href={`/posts/` + post._sys.filename}
passHref
Expand Down
7 changes: 6 additions & 1 deletion examples/tina-self-hosted-demo/components/util/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ export const Actions = ({
}
if (action.type === 'link' || action.type === 'linkExternal') {
element = (
<Link key={index} href={action.link ? action.link : '/'} passHref>
<Link
legacyBehavior
key={index}
href={action.link ? action.link : '/'}
passHref
>
<a
data-tinafield={`${parentField}.${index}`}
className={`group inline-flex items-center font-semibold text-lg transition duration-150 ease-out ${
Expand Down
13 changes: 13 additions & 0 deletions examples/tina-self-hosted-demo/content/users/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"users": [
{
"name": "Tina User",
"email": "user@tina.io",
"username": "tinauser",
"password": {
"value": "tinarocks",
"passwordChangeRequired": true
}
}
]
}
Loading

0 comments on commit a65ca13

Please sign in to comment.