Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃崻add cookieStorage for Tokens #807

Closed
agustif opened this issue Sep 16, 2019 · 3 comments 路 Fixed by #810
Closed

馃崻add cookieStorage for Tokens #807

agustif opened this issue Sep 16, 2019 · 3 comments 路 Fixed by #810

Comments

@agustif
Copy link
Contributor

agustif commented Sep 16, 2019

https://www.npmjs.com/package/cookie-storage
Let's add 馃崻Token Storage. so #802 and #804 can be resolved!

Thankfully there's already a package for that!
https://www.npmjs.com/package/cookie-storage

utils/accounts.ts

import { AccountsClient } from '@accounts/client';
import { AccountsClientPassword } from '@accounts/client-password';
import GraphQLClient from '@accounts/graphql-client';
import ApolloClient from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';
import fetch from 'isomorphic-fetch';
import { CookieStorage } from 'cookie-storage';

const cookieStorage = new CookieStorage();
const link = new HttpLink({
  uri: 'http://localhost:4000/graphql',
  fetch,
});
const cache = new InMemoryCache();
const apolloClient = new ApolloClient({
  link,
  cache,
});

const accountsGraphQL = new GraphQLClient({ graphQLClient: apolloClient });
const accountsClient = new AccountsClient(
  {
    // We tell the accounts-js client to use cookieStorage to store the tokens
    cookieStorage,
  },
  accountsGraphQL
);

const accountsPassword = new AccountsClientPassword(accountsClient);

export { accountsClient, accountsGraphQL, accountsPassword, apolloClient };

sadly trying to add tokenStorage: cookieStorage doesn't work.
Screenshot 2019-09-16 at 18 09 42

I will submit a PR for accounts/client basically cloning the token-local implementation to add a cookieStorage option!

I will also change the separator for the name, since : or semicolon's don't look nice in cookies it seems!
Screenshot 2019-09-16 at 01 21 09

Hopefully this is OK, not sure if much of a breaking change or something!

@stolinski
Copy link
Contributor

Yes please.

@agustif
Copy link
Contributor Author

agustif commented Sep 16, 2019

Hi @stolinski I actually have some version of working in my PR #804, you can take a look and give any feedback!

I actually messed up my local code, but I had it working all way down with SSR rendered homepage by reading cookies.

Hopefully someone else can clean it up and merge it to master!

@agustif
Copy link
Contributor Author

agustif commented Sep 16, 2019

Screenshots from PR #804
I think this are the most relevant changes for CookieStorage to work.

Screenshot 2019-09-16 at 19 35 41

Screenshot 2019-09-16 at 19 33 51

Screenshot 2019-09-16 at 19 33 39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants