Skip to content

Commit

Permalink
Merge pull request #2562 from opral/move-browser-auth-to-lix-client
Browse files Browse the repository at this point in the history
Move browser auth to lix client
  • Loading branch information
martin-lysk authored Apr 16, 2024
2 parents 52c1646 + 4941ca4 commit 791ebf1
Show file tree
Hide file tree
Showing 24 changed files with 245 additions and 173 deletions.
7 changes: 7 additions & 0 deletions .changeset/ten-suns-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@inlang/manage": patch
"@lix-js/client": patch
"@lix-js/server": patch
---

Moves getAuthClient from @lix-js/server to @lix-js/client and allows to inject ENV vars to make the pagacke independent from the env it runs in
1 change: 0 additions & 1 deletion inlang/source-code/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"dependencies": {
"@lix-js/client": "workspace:*",
"@lix-js/fs": "workspace:*",
"@lix-js/server": "workspace:*",
"@sentry/browser": "^7.27.0",
"@sentry/node": "^7.47.0",
"@sentry/tracing": "^7.47.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ import { Message } from "./Message.jsx"
import { Errors } from "./components/Errors.jsx"
import { Layout } from "./Layout.jsx"
import Link from "#src/renderer/Link.jsx"
import { browserAuth } from "@lix-js/server"
import { getAuthClient } from "@lix-js/client"
import { currentPageContext } from "#src/renderer/state.js"
import { replaceMetaInfo } from "./helper/ReplaceMetaInfo.js"
import { publicEnv } from "@inlang/env-variables"

const browserAuth = getAuthClient({
gitHubProxyBaseUrl: publicEnv.PUBLIC_GIT_PROXY_BASE_URL,
githubAppName: publicEnv.PUBLIC_LIX_GITHUB_APP_NAME,
githubAppClientId: publicEnv.PUBLIC_LIX_GITHUB_APP_CLIENT_ID,
})

export const [messageCount, setMessageCount] = createSignal(0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ import type { LocalStorageSchema } from "#src/services/local-storage/index.js"
import { useLocalStorage } from "#src/services/local-storage/index.js"
import type { TourStepId } from "./components/Notification/TourHintWrapper.jsx"
import { setSearchParams } from "./helper/setSearchParams.js"
import { openRepository, createNodeishMemoryFs, type Repository } from "@lix-js/client"
import { browserAuth } from "@lix-js/server"
import {
getAuthClient,
openRepository,
createNodeishMemoryFs,
type Repository,
} from "@lix-js/client"
import { publicEnv } from "@inlang/env-variables"
import {
LanguageTag,
Expand All @@ -33,6 +37,12 @@ import { posthog as telemetryBrowser } from "posthog-js"
import type { Result } from "@inlang/result"
import { id } from "../../../../../marketplace-manifest.json"

const browserAuth = getAuthClient({
gitHubProxyBaseUrl: publicEnv.PUBLIC_GIT_PROXY_BASE_URL,
githubAppName: publicEnv.PUBLIC_LIX_GITHUB_APP_NAME,
githubAppClientId: publicEnv.PUBLIC_LIX_GITHUB_APP_CLIENT_ID,
})

type EditorStateSchema = {
/**
* Returns a repository object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@ import {
} from "#src/services/auth/index.js"
import { posthog as telemetryBrowser } from "posthog-js"
import { TourHintWrapper, type TourStepId } from "./Notification/TourHintWrapper.jsx"
import { browserAuth } from "@lix-js/server"
import { getAuthClient } from "@lix-js/client"
import {
setSignInModalOpen,
signInModalOpen,
} from "#src/services/auth/src/components/SignInDialog.jsx"
import { WarningIcon } from "./Notification/NotificationHint.jsx"
import IconArrowDownward from "~icons/material-symbols/arrow-downward-alt"
import { debounce } from "throttle-debounce"
import { publicEnv } from "@inlang/env-variables"

const browserAuth = getAuthClient({
gitHubProxyBaseUrl: publicEnv.PUBLIC_GIT_PROXY_BASE_URL,
githubAppName: publicEnv.PUBLIC_LIX_GITHUB_APP_NAME,
githubAppClientId: publicEnv.PUBLIC_LIX_GITHUB_APP_CLIENT_ID,
})

export const Gitfloat = () => {
const {
Expand Down
8 changes: 7 additions & 1 deletion inlang/source-code/editor/src/services/auth/src/onSignOut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import type { SetStoreFunction } from "solid-js/store"
import type { LocalStorageSchema } from "../../../services/local-storage/index.js"
import { publicEnv } from "@inlang/env-variables"
import { posthog as telemetryBrowser } from "posthog-js"
import { browserAuth } from "@lix-js/server"
import { getAuthClient } from "@lix-js/client"

const browserAuth = getAuthClient({
gitHubProxyBaseUrl: publicEnv.PUBLIC_GIT_PROXY_BASE_URL,
githubAppName: publicEnv.PUBLIC_LIX_GITHUB_APP_NAME,
githubAppClientId: publicEnv.PUBLIC_LIX_GITHUB_APP_CLIENT_ID,
})

/**
* This function is called when the user clicks the "Sign Out" button.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { createEffect, createResource, Match, Switch } from "solid-js"
import { getAuthClient } from "@lix-js/client"
import MaterialSymbolsCheckCircleRounded from "~icons/material-symbols/check-circle-rounded"
import MaterialSymbolsArrowBackRounded from "~icons/material-symbols/arrow-back-rounded"
import { browserAuth } from "@lix-js/server"
import { publicEnv } from "@inlang/env-variables"
import { useLocalStorage } from "#src/services/local-storage/index.js"

const browserAuth = getAuthClient({
gitHubProxyBaseUrl: publicEnv.PUBLIC_GIT_PROXY_BASE_URL,
githubAppName: publicEnv.PUBLIC_LIX_GITHUB_APP_NAME,
githubAppClientId: publicEnv.PUBLIC_LIX_GITHUB_APP_CLIENT_ID,
})

/**
* The GitHub web application flow redirects to this page.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import { createContext, type JSXElement, onCleanup, onMount, useContext } from "
import { createStore, reconcile, type SetStoreFunction } from "solid-js/store"
import { defaultLocalStorage, type LocalStorageSchema } from "./schema.js"
import { posthog as telemetryBrowser } from "posthog-js"
import { browserAuth } from "@lix-js/server"
import { getAuthClient } from "@lix-js/client"
import { onSignOut } from "#src/services/auth/index.js"
import { publicEnv } from "@inlang/env-variables"

const browserAuth = getAuthClient({
gitHubProxyBaseUrl: publicEnv.PUBLIC_GIT_PROXY_BASE_URL,
githubAppName: publicEnv.PUBLIC_LIX_GITHUB_APP_NAME,
githubAppClientId: publicEnv.PUBLIC_LIX_GITHUB_APP_CLIENT_ID,
})

const LocalStorageContext = createContext()

const LOCAL_STORAGE_KEY = "inlang-local-storage"
Expand Down
1 change: 0 additions & 1 deletion inlang/source-code/manage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"clean": "rm -rf ./dist ./node_modules"
},
"devDependencies": {
"@lix-js/server": "workspace:*",
"@inlang/detect-json-formatting": "workspace:*",
"@inlang/env-variables": "workspace:*",
"@inlang/markdown": "workspace:*",
Expand Down
11 changes: 8 additions & 3 deletions inlang/source-code/manage/src/components/InlangInstall.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import type { TemplateResult } from "lit"
import { html } from "lit"
import { openRepository, createNodeishMemoryFs } from "@lix-js/client"
import { getAuthClient, openRepository, createNodeishMemoryFs } from "@lix-js/client"
import { customElement, property } from "lit/decorators.js"
import { TwLitElement } from "../common/TwLitElement.js"
import { browserAuth, getUser } from "@lix-js/server"
import { registry } from "@inlang/marketplace-registry"
import { ProjectSettings, loadProject, listProjects } from "@inlang/sdk"
import { detectJsonFormatting } from "@inlang/detect-json-formatting"
import { tryCatch } from "@inlang/result"
import { publicEnv } from "@inlang/env-variables"
import { z } from "zod"

const browserAuth = getAuthClient({
gitHubProxyBaseUrl: publicEnv.PUBLIC_GIT_PROXY_BASE_URL,
githubAppName: publicEnv.PUBLIC_LIX_GITHUB_APP_NAME,
githubAppClientId: publicEnv.PUBLIC_LIX_GITHUB_APP_CLIENT_ID,
})

@customElement("inlang-install")
export class InlangInstall extends TwLitElement {
@property({ type: Boolean })
Expand Down Expand Up @@ -228,7 +233,7 @@ export class InlangInstall extends TwLitElement {
// @ts-ignore
if (this.url.module) this.module = registry.find((x) => x.id === this.url.module)?.module

const auth = await getUser().catch(() => {
const auth = await browserAuth.getUser().catch(() => {
this.authorized = false
})
if (auth) {
Expand Down
12 changes: 9 additions & 3 deletions inlang/source-code/manage/src/components/InlangManage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ import { TwLitElement } from "../common/TwLitElement.js"
import { z } from "zod"
import "./InlangUninstall"
import "./InlangInstall"
import { createNodeishMemoryFs, openRepository } from "@lix-js/client"
import { getAuthClient, createNodeishMemoryFs, openRepository } from "@lix-js/client"
import { listProjects, isValidLanguageTag } from "@inlang/sdk"
import { publicEnv } from "@inlang/env-variables"
import { browserAuth, getUser } from "@lix-js/server"

import { tryCatch } from "@inlang/result"
import { registry } from "@inlang/marketplace-registry"
import type { MarketplaceManifest } from "../../../versioned-interfaces/marketplace-manifest/dist/interface.js"
import { posthog } from "posthog-js"
import { detectJsonFormatting } from "@inlang/detect-json-formatting"

const browserAuth = getAuthClient({
gitHubProxyBaseUrl: publicEnv.PUBLIC_GIT_PROXY_BASE_URL,
githubAppName: publicEnv.PUBLIC_LIX_GITHUB_APP_NAME,
githubAppClientId: publicEnv.PUBLIC_LIX_GITHUB_APP_CLIENT_ID,
})

type ManifestWithVersion = MarketplaceManifest & { version: string }

@customElement("inlang-manage")
Expand Down Expand Up @@ -230,7 +236,7 @@ export class InlangManage extends TwLitElement {

this.url.repo && this.projectHandler()

const user = await getUser().catch(() => {
const user = await browserAuth.getUser().catch(() => {
this.user = undefined
})
if (user) {
Expand Down
10 changes: 8 additions & 2 deletions inlang/source-code/manage/src/components/InlangUninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import { html } from "lit"
import { openRepository, createNodeishMemoryFs } from "@lix-js/client"
import { customElement, property } from "lit/decorators.js"
import { TwLitElement } from "../common/TwLitElement.js"
import { browserAuth, getUser } from "@lix-js/server"
import { getAuthClient } from "@lix-js/client"
import { registry } from "@inlang/marketplace-registry"
import { ProjectSettings } from "@inlang/sdk"
import { detectJsonFormatting } from "@inlang/detect-json-formatting"
import { tryCatch } from "@inlang/result"
import { publicEnv } from "@inlang/env-variables"

const browserAuth = getAuthClient({
gitHubProxyBaseUrl: publicEnv.PUBLIC_GIT_PROXY_BASE_URL,
githubAppName: publicEnv.PUBLIC_LIX_GITHUB_APP_NAME,
githubAppClientId: publicEnv.PUBLIC_LIX_GITHUB_APP_CLIENT_ID,
})

@customElement("inlang-uninstall")
export class InlangInstall extends TwLitElement {
@property({ type: Boolean })
Expand Down Expand Up @@ -164,7 +170,7 @@ export class InlangInstall extends TwLitElement {
super.connectedCallback()
this.url = JSON.parse(this.jsonURL)

const auth = await getUser().catch(() => {
const auth = await browserAuth.getUser().catch(() => {
this.authorized = false
})
if (auth) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/**
* @param {string} param
* @returns {param is number}
*/
export function match(param) {
Expand Down
1 change: 0 additions & 1 deletion inlang/source-code/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"dependencies": {
"@lix-js/client": "workspace:*",
"@lix-js/fs": "workspace:*",
"@lix-js/server": "workspace:*",
"@sentry/browser": "^7.27.0",
"@sentry/node": "^7.47.0",
"@sentry/tracing": "^7.47.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import type { SetStoreFunction } from "solid-js/store"
import type { LocalStorageSchema } from "../../../services/local-storage/index.js"
import { telemetryBrowser } from "@inlang/telemetry"
import { browserAuth } from "@lix-js/server"
import { getAuthClient } from "@lix-js/client"
import { publicEnv } from "@inlang/env-variables"

const browserAuth = getAuthClient({
gitHubProxyBaseUrl: publicEnv.PUBLIC_GIT_PROXY_BASE_URL,
githubAppName: publicEnv.PUBLIC_LIX_GITHUB_APP_NAME,
githubAppClientId: publicEnv.PUBLIC_LIX_GITHUB_APP_CLIENT_ID,
})

/**
* This function is called when the user clicks the "Sign Out" button.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { createEffect, createResource, Match, Switch } from "solid-js"
import MaterialSymbolsCheckCircleRounded from "~icons/material-symbols/check-circle-rounded"
import MaterialSymbolsArrowBackRounded from "~icons/material-symbols/arrow-back-rounded"
import { browserAuth } from "@lix-js/server"
import { getAuthClient } from "@lix-js/client"
import { useLocalStorage } from "#src/services/local-storage/index.js"
import { publicEnv } from "@inlang/env-variables"

const browserAuth = getAuthClient({
gitHubProxyBaseUrl: publicEnv.PUBLIC_GIT_PROXY_BASE_URL,
githubAppName: publicEnv.PUBLIC_LIX_GITHUB_APP_NAME,
githubAppClientId: publicEnv.PUBLIC_LIX_GITHUB_APP_CLIENT_ID,
})
/**
* The GitHub web application flow redirects to this page.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import { createContext, type JSXElement, onCleanup, onMount, useContext } from "
import { createStore, reconcile, type SetStoreFunction } from "solid-js/store"
import { defaultLocalStorage, type LocalStorageSchema } from "./schema.js"
import { telemetryBrowser } from "@inlang/telemetry"
import { browserAuth } from "@lix-js/server"
import { getAuthClient } from "@lix-js/client"
import { onSignOut } from "#src/services/auth/index.js"
import { publicEnv } from "@inlang/env-variables"

const browserAuth = getAuthClient({
gitHubProxyBaseUrl: publicEnv.PUBLIC_GIT_PROXY_BASE_URL,
githubAppName: publicEnv.PUBLIC_LIX_GITHUB_APP_NAME,
githubAppClientId: publicEnv.PUBLIC_LIX_GITHUB_APP_CLIENT_ID,
})

const LocalStorageContext = createContext()

const LOCAL_STORAGE_KEY = "inlang-local-storage"
Expand Down
Loading

0 comments on commit 791ebf1

Please sign in to comment.