Comments (6)
The question here is, if someone built an alternate network interface, would an existing login middleware work with it? It seems like the answer is probably no, because only an HTTP network interface would have a login middleware that uses headers. So it makes sense that it would be attached to the network interface I guess.
Everything you said sounds good then.
from apollo-client.
@stubailo that is what @johnthepink had too 👍 Let's go with that direction for the auth middleware
from apollo-client.
Closed via #75
from apollo-client.
A few notes:
- the middleware can modify both the options passed to the request, and the headers by passing a compliant
RequestInit
object - we should document that the following fields are reserved
body, headers.Accept, headers.Content-Type, method
and probably warn if they are sent - the authentication middleware should only affect the headers. (Unless I'm missing another need?)
Since the network interface can be supplied to the client, I think having the middleware be attached to it makes the most sense. We could pretty easily return a way to apply middleware to the default network interface through the client object. public registerNetworkMiddleware
seems a good enough solution
from apollo-client.
@stubailo @johnthepink and I talked through a few options for this. What are your thoughts on https://gist.github.com/jbaxleyiii/e899fe74842b7488657617e43c9a30fe
// the meat of the gist
const heighliner = createNetworkInterface('http://localhost:8888/');
interface MiddlewareRequest {
request: Request;
options: RequestInit;
}
// option 1, generic middleware that can modify the options of the request
const tokenMiddleware = (request: MiddlewareRequest, next: function): void => {
// this would be called on each request and has the option to modify the headers
// this doesn't return a value, but rather modifies the request inline.
// that feels gross but I don't know of another way to do next() unless you pass
// the request into next? which also seems odd
};
// option 2, authorization sugaring of option 1 that only modifies the headers
// and defaults to setting an 'Authorization' header.
heighliner.authorize('token': string, /* optional key name for token : string*/);
heighliner.removeAuthorization(/* probably just a null value here? */);
// the middleware would be on the networkInterface itself
// should this be an array? or allow for multiple arugments to be passed as args
// e.g. `use(middleware1, middleware2, etc)
heighliner.use(tokenMiddleware);
from apollo-client.
heighliner.authorize
is this better than something like:
const authMiddleware = new AuthTokenHeaderMiddleware();
heighliner.use([
authMiddleware,
]);
authMiddleware.setToken(token);
authMiddleware.setToken(null);
Also, I think use
should always take an array probably.
Other than that, looks really good! I think going with the express model where you modify the object is probably the best.
from apollo-client.
Related Issues (20)
- Error: Unsatisfied version 0 from platform of shared singleton module @apollo/client/core (required ^3.8.9) HOT 3
- Format of incremental delivery responses HOT 2
- Cursor Pagination issue preview page HOT 2
- Fuzzy type policies don't support type-level `merge` functions HOT 4
- "Cannot convert object to primitive value" error happens when "Cache data may be lost ..." warning is output on dev console HOT 1
- Can't disable cache normalization globally HOT 3
- Infinite suspense loop in useSuspenseQuery if the same query document is first skipped, then fetched in the same suspense boundary HOT 5
- Write documentation for `useLoadableQuery` HOT 2
- Migrate parts of our API documentation into autogenerated docs HOT 3
- Write documentation for new `createQueryPreloader`/`preloadQuery` APIs HOT 3
- Write documentation for new `useQueryRefHandlers` hook HOT 3
- fragment causes client data to be empty object when network tab retrieves expected data HOT 5
- It's unclear that headers prop only works when there is no link prop HOT 5
- Stabilize `createQueryPreloader`/`preloadQuery` API
- useFragment is not scalable as the number of fragment grows HOT 1
- Feedback for React query preloading feature HOT 4
- Incoming data partially not normalized when matching a fuzzy possibleType and selected on a fragment when nullable field is null
- Introduce skipToken to useQuery HOT 7
- watchQuery with "network-only" policy does not fire when optimistic data is written to cache HOT 2
- Sub-nested fields or subfields on Apollo Client Type Policies HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo-client.