New lix client api #1386
Replies: 7 comments 6 replies
-
An alternative could be an auth object which optionally gets passed to const auth = await authenticate()
const repo = await openRepository(`https://lix.inlang.com/git/${host}/{owner}/{repository}`, { nodeishFs, auth }) Pros
Cons
|
Beta Was this translation helpful? Give feedback.
-
I think we can go either way. Let's not make a big deal out of this decision. I slightly prefer the auth object passed to open repository direction as |
Beta Was this translation helpful? Give feedback.
-
i am not sure we should burden the apps to carry around auth or user objects and pass that to apis that need them. also another issue is that the login is depending on the environment not directly acccesible. for example in browser environments the token is inside a http only cookie so it would be not obvious how to handle the auth object (eg. you would still be logged in if you do not pass the object to the api and if you login again and save both objects you could not use two auth objects simultaneously as you would expect ..). if the auth is jsut internal state of the lixClient this would be much simpler to reason about. the auth api with my proposal would be explicit: const lixClient = await createLixClient({
lixUrl: publicEnv.PUBLIC_LIX_URL,
})
const user = await lixClient.getUser()
if (!user) {
await lixClient.login() // only required if you want to do things that require a login or further rights, you could locally open a public repo
}
const newRepo = await lixClient.openRepository(`${host}/${owner}/${repository}`, {
nodeishFs: createNodeishMemoryFs()
}) implicit: const lixClient = await createLixClient({
lixUrl: publicEnv.PUBLIC_LIX_URL,
// something like this could automatically trigger login()
// when an action is not possible anonymous, but would until such action is tried login could be postponed
autoLogin: true
})
const newRepo = await lixClient.openRepository(`${host}/${owner}/${repository}`, {
nodeishFs: createNodeishMemoryFs()
}) |
Beta Was this translation helpful? Give feedback.
-
Hm. The auth module/object only needs to be passed to const auth = await authenticate()
const repo = await openRepository(`https://lix.inlang.com/git/${host}/{owner}/{repository}`, { nodeishFs, auth }) I am wary of
My proposal of passing modules as required to open the repository seems to increase the flexibility of a lix client and ease maintenance.
The code below is essentially your proposal except that the auth module doesn't return a lix client but an auth object which can be passed to openRepository. import { webAppLogin } from "@lix-js/auth"
const user = await webAppLogin()
const repo = await openRepository("https://lix.inlang.com/git/github.com/inlang/monorepo", {
nodeishFs,
auth: user
})
// or server side
import { nodeAuth } from "@lix-js/auth"
const user = await nodeAuth()
const repo = await openRepository("https://lix.inlang.com/git/github.com/inlang/monorepo", {
nodeishFs,
auth: user
}) |
Beta Was this translation helpful? Give feedback.
-
My 2 ct's on this topic: Consider multiple "remotes"With the current approach a repository is bound to an uri. I would challange this because with the goal to have an offline first system with remotes doing distribution in the next steps it's not unlikely that one repository - cloned or created locally - eventually has multiple remotes - like the remotes concept of git. Why I bring this up here: Introduce a class - provider or host that contains auth and a provider could become a reference of a remoteProvider or hosts should be a separate object independend from repositories - If I use the inlang editor I see two scenarios:
By separating Provider from repo - this would be possible. I could than clone a repo using the provider i have configured. |
Beta Was this translation helpful? Give feedback.
-
ok got a new proposal, please keep in mind this does not have to be anything final or super flexible we just need a good structure to move on with the restructuring, this will certainly change again when we build our real auth system and permissions. think of this as something in between the current hard coded auth in the editor and the final lix api. this is basically samuels proposal with slightly different auth object in a browser context, as it otherwise wont work for http only cookies where auth is just an inaccessible hidden state of the browser and would lead to misconceptions how the object would behave. Also getUser should be seperate from the login as this requires requests for user data which might not be required. in browser import { browserAuth, openRepository } from "@lix-js/client"
const auth = browserAuth({ lixUrl: 'https://lix.inlang.com' })
// auth is optional, creating a lixclient explicitly is not required anymore you can directly call openRepository for anon things
const user = await auth.getUser()
if (!user?.loggedIn) {
await auth.login()
}
const repo = await openRepository("https://lix.inlang.com/git/github.com/inlang/monorepo", {
nodeishFs,
auth
})
await auth.logout() on server import { openRepository, tokenAuth } from "@lix-js/client"
const auth = tokenAuth({token:'whatever', settings: ...})
const repo = await openRepository("https://lix.inlang.com/git/github.com/inlang/monorepo", {
nodeishFs,
auth
}) |
Beta Was this translation helpful? Give feedback.
-
@samuelstroschein ping me when you read the last proposal and have a minute, maybe we can make a decision in around |
Beta Was this translation helpful? Give feedback.
-
We will have to do changes to the lix client api in order to facilitate things like userinfo and login/logout, which would not live on the repo level, but it would be awkward to have to supply the info where lix is running in every api call.
my first proposa:
instead of
the new api would look like this:
Beta Was this translation helpful? Give feedback.
All reactions