[{"_path":"/getting-started/auth-helpers","_draft":false,"_partial":false,"_empty":false,"title":"Auth Helpers","description":"Helper functions for working with authentication in Apollo.","excerpt":{"type":"root","children":[{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Nuxt Apollo provides three (3) auth helpers which can be easily plugged into your authentication flow to interface with configured Apollo clients."}]},{"type":"element","tag":"h2","props":{"id":"gettoken"},"children":[{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"getToken"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Retrieve the auth token token for the specified client."}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"This adheres to the "},{"type":"element","tag":"a","props":{"href":"/recipes/authentication#auth-hook"},"children":[{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"apollo:auth"}]},{"type":"text","value":" hook"}]},{"type":"text","value":". and will attempt to automatically retrieve the token from the "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"apollo:auth"}]},{"type":"text","value":" hook."}]},{"type":"element","tag":"code","props":{"code":"const { getToken } = useApollo()\n\nconst token = getToken()\n\nconst otherToken = getToken('')\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"const { getToken } = useApollo()\n\nconst token = getToken()\n\nconst otherToken = getToken('')\n"}]}]}]},{"type":"element","tag":"h3","props":{"id":"gettoken-reference"},"children":[{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"getToken"}]},{"type":"text","value":" Reference"}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"client"}]},{"type":"text","value":": The Apollo client who's token should be retrieved."}]}]},{"type":"element","tag":"h2","props":{"id":"onlogin"},"children":[{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"onLogin"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Used to apply the given auth token to the specified Apollo client. This is required if your GraphQL API expects authentication to be passed via a HTTP header."}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"By default, this function will reset the Apollo client cache and re-execute all queries, this behavior can be averted by passing "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"false"}]},{"type":"text","value":" as the third parameter ("},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"skipResetStore"}]},{"type":"text","value":")."}]},{"type":"element","tag":"code","props":{"code":"const { onLogin } = useApollo()\n\nfunction handleLogin() {\n // your login flow...\n\n onLogin(token)\n}\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"const { onLogin } = useApollo()\n\nfunction handleLogin() {\n // your login flow...\n\n onLogin(token)\n}\n"}]}]}]},{"type":"element","tag":"h3","props":{"id":"onlogin-reference"},"children":[{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"onLogin"}]},{"type":"text","value":" Reference"}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"token"}]},{"type":"text","value":": The token to be applied."}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"client"}]},{"type":"text","value":": The Apollo client to authenticate."},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Default: "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"default"}]}]}]}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"skipResetStore"}]},{"type":"text","value":": Whether to skip resetting the Apollo client cache."},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Default: "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"false"}]}]}]}]}]},{"type":"element","tag":"h2","props":{"id":"onlogout"},"children":[{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"onLogout"}]}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Used to remove the auth token from the specified Apollo client."}]},{"type":"element","tag":"code","props":{"code":"const { onLogout } = useApollo()\n\nfunction handleLogout() {\n // your logout flow...\n\n onLogout()\n}\n","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"const { onLogout } = useApollo()\n\nfunction handleLogout() {\n // your logout flow...\n\n onLogout()\n}\n"}]}]}]},{"type":"element","tag":"h3","props":{"id":"onlogout-reference"},"children":[{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"onLogout"}]},{"type":"text","value":" Reference"}]},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"client"}]},{"type":"text","value":": The Apollo client to de-authenticate."},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Default: "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"default"}]}]}]}]},{"type":"element","tag":"li","props":{},"children":[{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"skipResetStore"}]},{"type":"text","value":": Whether to skip resetting the Apollo client cache."},{"type":"element","tag":"ul","props":{},"children":[{"type":"element","tag":"li","props":{},"children":[{"type":"text","value":"Default: "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"false"}]}]}]}]}]}]},"_type":"markdown","_id":"content:1.getting-started:4.auth-helpers.md","_source":"content","_file":"1.getting-started/4.auth-helpers.md","_extension":"md"},{"_path":"/recipes/error-handling","_draft":false,"_partial":false,"_empty":false,"title":"Error Handling","description":"Capture GraphQL errors and handle them accordingly.","excerpt":{"type":"root","children":[{"type":"element","tag":"h2","props":{"id":"error-policy"},"children":[{"type":"text","value":"Error Policy"}]},{"type":"element","tag":"h2","props":{"id":"error-hook"},"children":[{"type":"text","value":"Error Hook"}]},{"type":"element","tag":"p","props":{},"children":[{"type":"text","value":"Nuxt Apollo provides a nuxt hook named "},{"type":"element","tag":"code-inline","props":{},"children":[{"type":"text","value":"apollo:error"}]},{"type":"text","value":" which captures errors encountered by apollo client(s)."}]},{"type":"element","tag":"code","props":{"code":"export default defineNuxtPlugin((nuxtApp) => {\n nuxtApp.hook('apollo:error', (error) => {\n console.error(error)\n\n // Handle different error cases\n })\n})\n","filename":"plugins/apollo.ts","language":"ts"},"children":[{"type":"element","tag":"pre","props":{},"children":[{"type":"element","tag":"code","props":{"__ignoreMap":""},"children":[{"type":"text","value":"export default defineNuxtPlugin((nuxtApp) => {\n nuxtApp.hook('apollo:error', (error) => {\n console.error(error)\n\n // Handle different error cases\n })\n})\n"}]}]}]}]},"_type":"markdown","_id":"content:2.recipes:2.error-handling.md","_source":"content","_file":"2.recipes/2.error-handling.md","_extension":"md"}]