Comments (8)
How are you logging in the user? I ask, because normally you'd need to contact the server first to validate credentials and for that, you need the GraphQL connection.
Scott
from app-extension-apollo.
I am using laravel sanctum and I check the user log status based on the cookies. The user logs in from a standard login page. I created a boot file that check before each route navigation if the user is connected.
from app-extension-apollo.
And, how do you check if a user is "connected"? Somehow you need to connect (via GraphQL?) to the server, right? So, the first thing should be, send a request to the server about the user at hand (and validate access token/ session) and if all is well, the user can continue. If not, they get redirected to your login page. In other words, your SPA should access the API server first (to authenticate the user as "ok" or not), then route the user accordingly. The boot sequence should be fine.
Scott
from app-extension-apollo.
GraphQL might not be a part of authentication process, as there can exists dedicated identity server, STS.
First, SPA communicates with other URI (token issuer) via oidc-client, then passed access token to the API.
So login page does not touch apollo, as there is no token yet. It shows transient screen, which launches browser redirect to STS with OpenID Connect / OAuth 2 process. When user is logged in at STS (like Google does), it redirects back to SPA (to the 'complete sign-in' page, specified in the STS configuration for that client).
In application workflow, there is action, known as 'silent refresh' where tokens are rotating in the background (within iframe with redirects to STS and back).
Apollo will be disconnected without token:
Navigated to https://localhost:8080/
[HMR] Waiting for update signal from WDS...
[Quasar] Running SPA.
Can access to '/': No.
Can access to '/sign-in': Yes. <-- Showing splash-screen before navigating to STS
[ApolloClient] Connecting...
[ApolloClient] Disconnected.
UserManager.signinRedirect: successful <-- Now received STS data to start navigation on it
[WDS] Hot Module Replacement enabled.
[WDS] Live Reloading enabled.
[ApolloClient] Reconnecting...
[ApolloClient] Disconnected.
Navigated to https://localhost:5001 <-- This where user was authenticated at STS
Navigated to https://localhost:8080/sign-in/complete <-- landing page after authentication
[HMR] Waiting for update signal from WDS...
[Quasar] Running SPA.
Can access to '/sign-in/complete': Yes.
[ApolloClient] Connecting...
[ApolloClient] Disconnected.
[WDS] Hot Module Replacement enabled.
[WDS] Live Reloading enabled.
[ApolloClient] Reconnecting...
[ApolloClient] Disconnected.
[ApolloClient] Reconnecting...
[ApolloClient] Disconnected.
[ApolloClient] Reconnecting...
[ApolloClient] Disconnected.
UserManager.signinRedirectCallback: successful, signed in sub: xxxxxxxxx
UserManager.getUser: user loaded
Can access to '/': Yes.
DefaultLayout.vue CREATED DEFAULT
Index.vue CREATED INDEX
[ApolloClient] Reconnecting...
[ApolloClient] Reconnected. <-- This is where API allowed to connect Apollo.
After a time:
[IdentityManager] Renewing silently...
UserManager.signinSilent: successful, signed in sub: xxxxxxxxx
from app-extension-apollo.
Found that we can set lazy: true
to prevent auto-connection before any client action being allowed.
SubscriptionClient parameters can be found at this description.
So original question is not about current 'apollo extension' repo, but how Quasar boot system works to exclude some steps from it.
from app-extension-apollo.
@smolinari Actually, you are right, I was using the connection in the wrong place of the boot file.
@Arsync I don't understand what you mean
from app-extension-apollo.
I don't understand what you mean
This will manifest itself when you start using websockets and subscriptions. Apollo in my case agressivly tried to connect even on log-in screen. So I've looked for exactly same solution to disable boot files. But found just 'lazy' property:
// apollo-client-hooks
export function apolloClientBeforeCreate({ apolloClientConfigObj, app /*, router, store, ssrContext, urlPath, redirect */ })
{
const subClient = new SubscriptionClient(
process.env.API_GRAPHQL_WSS_URI,
{
lazy: true, // <-- this one to get connected on first API call
reconnect: true,
timeout: 30000,
connectionParams: getConnectionParams(app.identity), // solution-specific function, nevermind
}
);
const link = new WebSocketLink(subClient);
apolloClientConfigObj.link = link;
}
from app-extension-apollo.
This question seems answered so closing.
Scott
from app-extension-apollo.
Related Issues (20)
- Infinite loading on SSR HOT 5
- Quasar 2 + Apollo: Error: Apollo client with id default not found. Use provideApolloClient() if you are outside of a component setup HOT 9
- quasar build -m pwa not using GRAPHQL_URI HOT 3
- Extension v2 doesn't install due to @quasar/app dependency missing in quasar vite setup HOT 1
- this.$apollo returns `undefined` HOT 1
- installation breaks using vite HOT 4
- Error: Apollo client with id default not found. Use provideApolloClient() if you are outside of a component setup, in the q-dialog (modal) HOT 3
- Minor request HOT 1
- First call affter Page reload anytime gives me an undefined HOT 8
- HELP USING LIB HOT 7
- graphql-tag dependency issues HOT 2
- Apollo Client not compatible with Quasar II ? HOT 2
- Invalid Version: undefined Exception when installing HOT 2
- Error in Quasar ssr with @vue/apollo-composable HOT 6
- lient id
- @vue/apollo-composable HOT 2
- Quasar v2 ssr mode and apollo extension HOT 3
- [Quasar] boot error: SyntaxError: missing name after . operator HOT 2
- Add support for SSR
- JWT token for apollo client. 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 app-extension-apollo.