Skip to content
This repository was archived by the owner on Aug 23, 2021. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/dry-coats-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'demo': minor
'tina-tailwind-sidebar-demo': minor
'next-tinacms-cloudinary': minor
'tina-cloud-next': minor
'tina-graphql-gateway': minor
---

Merge main into use-v2-cloud-api
1 change: 0 additions & 1 deletion apps/demo/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ function MyApp({ Component, pageProps }: AppProps) {
const client = new LocalClient()
// const client = new Client({
// clientId: 'some-id',
// organizationId: 'gctc',
// branch: 'main',
// })

Expand Down
1 change: 0 additions & 1 deletion examples/tina-tailwind-sidebar-demo/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const createCloudClient = () => {
}

return new Client({
organizationId: organization,
clientId,
branch: 'tina-cloud',
tokenStorage: 'LOCAL_STORAGE',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export class TinaCloudCloudinaryMediaStore extends CloudinaryMediaStore {
this.fetchFunction = async (input: RequestInfo, init?: RequestInit) => {
try {
const url = input.toString()
const query = `${url.includes('?') ? '&' : '?'}org=${
client.organizationId
}&clientID=${client.clientId}`
const query = `${url.includes('?') ? '&' : '?'}clientID=${
client.clientId
}`

const res = client.fetchWithToken(url + query, init)
return res
Expand Down
2 changes: 1 addition & 1 deletion packages/tina-cloud-next/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const cms = useCMS()
const tinaCloudClient: Client = cms.api.tina
const uploadImage = async () => {
const req = await tinaCloudClient.fetchWithToken(
`/api/upload?org=${tinaCloudClient.organizationId}&clientID=${tinaCloudClient.clientId}`
`/api/upload?clientID=${tinaCloudClient.clientId}`
)
console.log({ test: await test.json() })
}
Expand Down
2 changes: 1 addition & 1 deletion packages/tina-cloud-next/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const isAuthorized = async (
try {
// fetch identity from content server
const tinaCloudRes = await fetch(
`https://identity.tinajs.io/realm/${org}/${clientID}/currentUser`,
`https://identity.tinajs.io/v2/apps/${clientID}/currentUser`,
{
headers: new Headers({
'Content-Type': 'application/json',
Expand Down
1 change: 0 additions & 1 deletion packages/tina-graphql-gateway/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ This package exports a class which acts as [TinaCMS external API](https://tina.i
```ts
import { Client, LocalClient } from "tina-graphql-gateway";
const client = new Client({
organizationId: "the ID you get from Tina Cloud",
clientId: "the client ID you get from Tina Cloud",
branch: "main",
tokenStorage: "LOCAL_STORAGE" | "MEMORY" | "CUSTOM",
Expand Down
10 changes: 4 additions & 6 deletions packages/tina-graphql-gateway/src/auth/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ import popupWindow from './popupWindow'
const TINA_LOGIN_EVENT = 'tinaCloudLogin'
export const AUTH_TOKEN_KEY = 'tinacms-auth'

const BASE_TINA_URL = process.env.BASE_TINA_URL || `tina.io`
const BASE_TINA_URL = process.env.BASE_TINA_URL || `app.tina.io`

export type TokenObject = {
id_token: string
access_token: string
refresh_token: string
}
export const authenticate = (
clientId: string,
organizationId: string
): Promise<TokenObject> => {
export const authenticate = (clientId: string): Promise<TokenObject> => {
return new Promise((resolve) => {
// @ts-ignore
let authTab: Window | undefined
Expand All @@ -44,8 +41,9 @@ export const authenticate = (
})
}
})
const origin = `${window.location.protocol}//${window.location.host}`
authTab = popupWindow(
`https://${organizationId}.${BASE_TINA_URL}/signin?clientId=${clientId}`,
`https://${BASE_TINA_URL}/signin?clientId=${clientId}&origin=${origin}`,
'_blank',
window,
1000,
Expand Down
16 changes: 6 additions & 10 deletions packages/tina-graphql-gateway/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import gql from 'graphql-tag'
import { transformPayload } from './transform-payload'

interface ServerOptions {
organizationId: string
clientId: string
branch: string
customContentApiUrl?: string
Expand All @@ -41,7 +40,6 @@ const CONTENT_API_URL =

export class Client {
contentApiUrl: string
organizationId: string
schema: GraphQLSchema
clientId: string
query: string
Expand All @@ -56,12 +54,11 @@ export class Client {
* https://github.com/tinacms/tina-graphql-gateway/issues/219
*/
const encodedBranch = encodeURIComponent(options.branch)
;(this.contentApiUrl =
this.contentApiUrl =
options.customContentApiUrl ||
`${CONTENT_API_URL}/content/${options.organizationId}/${options.clientId}/github/${encodedBranch}`),
// `https://content.tinajs.dev/content/${options.organizationId}/${options.clientId}/github/${encodedBranch}`),
(this.clientId = options.clientId)
this.organizationId = options.organizationId
`${CONTENT_API_URL}/content/${options.clientId}/github/${encodedBranch}`

this.clientId = options.clientId

switch (tokenStorage) {
case 'LOCAL_STORAGE':
Expand Down Expand Up @@ -230,7 +227,7 @@ export class Client {
}

async authenticate() {
const token = await authenticate(this.clientId, this.organizationId)
const token = await authenticate(this.clientId)
this.setToken(token)
return token
}
Expand Down Expand Up @@ -258,7 +255,7 @@ export class Client {
}

async getUser() {
const url = `${IDENTITY_API_URL}/realm/${this.organizationId}/${this.clientId}/currentUser`
const url = `${IDENTITY_API_URL}/v2/apps/${this.clientId}/currentUser`

try {
const res = await this.fetchWithToken(url, {
Expand All @@ -284,7 +281,6 @@ export const DEFAULT_LOCAL_TINA_GQL_SERVER_URL = 'http://localhost:4001/graphql'
export class LocalClient extends Client {
constructor(props?: { customContentApiUrl?: string }) {
const clientProps = {
organizationId: '',
clientId: '',
branch: '',
customContentApiUrl:
Expand Down
6 changes: 1 addition & 5 deletions packages/tina-graphql-gateway/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ export const createClient = ({
export const createCloudClient = (
props: Omit<CreateClientProps, 'isLocalClient'>
) => {
const organization = props.organization
const clientId = props.clientId

const missingProps: string[] = []
if (!organization) {
missingProps.push('organization')
}

if (!clientId) {
missingProps.push('clientId')
}
Expand All @@ -52,7 +49,6 @@ export const createCloudClient = (
}

return new Client({
organizationId: organization,
clientId,
branch: props.branch || 'main',
tokenStorage: 'LOCAL_STORAGE',
Expand Down