-
Notifications
You must be signed in to change notification settings - Fork 77
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
Keeping context between calbacks #94
Comments
I think adding a context object specifically for passing around data would be great. I am hesitant to just add this to a req object as that can change. I am totally cool for this to be added, if you open a PR I can help shepherd it through. |
Ok, working on this I see the root of the issue is that a service call is performed in a separate request to authentication. So the server will have to authenticate twice. I think that's fine and users of the lib can cache their auth info if they like. But I'm ending up doing a bit of a refactor to make the request flow a bit clearer to me. I've simplified the possible authenticate?: (options: GitAuthenticateOptions) => Promise<T> | T; (and simplified the So usage looks something like this: const repos = new Git<number>(repoDir, {
autoCreate: true,
authenticate: async (options) => {
const [username, password] = await options.getUser(); // throws on failure rather than writing to res
if (username !== "me" || password !== "foo") {
throw new Error("username or password incorrect");
}
return { a: 42, username: username };
},
});
repos.on("push" ({ context }) => context.a === 42); |
Opened a PR of my WIP - seems to work fine for me but I'd like to add more tests |
We have a
get-user-repo-access-info
procedure which is asynchronous - we run this in theauthenticate
callback as passed into theGit
constructor. We do this to deny access to users before this library even looks for a git repo to use. However when we then get to thepush
event listener we're struggling to see how we can equate the original request with this specific callback. There is no shared state passed into the listener.Would you be willing to help us rectify this? Honestly I'd be fine with just adding
http.IncomingMessage
to theGitAuthenticateOptions
asreq
- I can then just add a property to that object 🤷It looks as though you've maybe kept the
authenticate
callback to accept the bare minimum of information though - if there's a specific reason for that perhaps we could add an emptycontext
object to theauthenticate
callback which can then be passed to later event handlers. Avoiding giving the authenticate method any additional data to be mis-understood or used.Thanks for the very helpful library, happy to open a PR for this, just wanted an idea of what is more likely to be merged.
The text was updated successfully, but these errors were encountered: