Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
uri: options.uri,
}),
]),
});
const client = new AccountsClient(
options,
new AccountsGraphQLClient({
graphQLClient: apollo,
})
);
let password;
if (require.resolve('@accounts/client-password')) {
const AccountsClientPassword = require('@accounts/client-password').AccountsClientPassword; // tslint:disable-line no-implicit-dependencies
password = new AccountsClientPassword(client, options.password);
}
return {
client,
apollo,
link: accountsLink(client),
password,
};
};
// This auth link will inject the token in the headers on every request you make using apollo client
const authLink = accountsLink(() => accountsClient);
const httpLink = new HttpLink({
uri: 'http://localhost:4000/graphql',
});
const apolloClient = new ApolloClient({
link: from([authLink, httpLink]),
cache: new InMemoryCache(),
});
const accountsGraphQL = new GraphQLClient({ graphQLClient: apolloClient });
const accountsClient = new AccountsClient({}, accountsGraphQL);
const accountsPassword = new AccountsClientPassword(accountsClient);
export { accountsClient, accountsGraphQL, accountsPassword, apolloClient };
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
tokenStorage: cookieStorage,
},
accountsGraphQL
);
const accountsPassword = new AccountsClientPassword(accountsClient);
export { accountsClient, accountsGraphQL, accountsPassword, apolloClient };
);
/**
* Setup express
*/
this.app = express();
this.app.use(bodyParser.json());
this.app.use(bodyParser.urlencoded({ extended: true }));
this.app.use(accountsExpress(this.accountsServer));
const accountsRest = new RestClient({
apiHost: `http://localhost:${this.port}`,
rootPath: '/accounts',
});
this.accountsClient = new AccountsClient({}, accountsRest);
this.accountsClientPassword = new AccountsClientPassword(this.accountsClient);
this.emails = [];
}
const { schema, context } = AccountsModule.forRoot({
accountsServer: this.accountsServer,
});
this.apolloServer = new ApolloServer({
schema,
context,
});
const apolloClient = new ApolloClient({ uri: `http://localhost:${this.port}` });
const accountsClientGraphQL = new AccountsGraphQLClient({
graphQLClient: apolloClient,
});
this.accountsClient = new AccountsClient({}, accountsClientGraphQL);
this.accountsClientPassword = new AccountsClientPassword(this.accountsClient);
this.emails = [];
}
constructor(apolloClient, accountsClientOptions) {
const accountsGraphQL = new GraphQLClient({ graphQLClient: apolloClient })
const accountsClient = new AccountsClient(
accountsClientOptions,
accountsGraphQL
)
const accountsPassword = new AccountsClientPassword(accountsClient)
this.accountsGraphQL = accountsGraphQL
this.accountsClient = accountsClient
this.accountsPassword = accountsPassword
this.createUser = accountsPassword.createUser.bind(accountsPassword)
this.login = accountsPassword.login.bind(accountsPassword)
this.refreshSession = accountsClient.refreshSession.bind(accountsClient)
this.logout = accountsClient.logout.bind(accountsClient)
this.getUser = accountsGraphQL.getUser.bind(accountsGraphQL)
this.sendVerificationEmail = accountsGraphQL.sendVerificationEmail.bind(
accountsGraphQL
)
this.verifyEmail = accountsGraphQL.verifyEmail.bind(accountsGraphQL)
import { AccountsClient } from '@accounts/client';
import { AccountsClientPassword } from '@accounts/client-password';
import { RestClient } from '@accounts/rest-client';
const accountsRest = new RestClient({
apiHost: process.env.REACT_APP_API_URL!,
rootPath: '/accounts',
});
const accountsClient = new AccountsClient({}, accountsRest);
const accountsPassword = new AccountsClientPassword(accountsClient);
export { accountsClient, accountsRest, accountsPassword };
const withToken = setContext(() => {
return {
headers: {
'x-prime-token': localStorage.getItem('accounts:accessToken'),
},
};
});
const client = new ApolloClient({
link: concat(withToken, httpLink),
cache: new InMemoryCache(),
});
const accountsGraphQL = new GraphQLClient({ graphQLClient: client });
const accountsClient = new AccountsClient({}, accountsGraphQL);
const accountsPassword = new AccountsClientPassword(accountsClient);
export { accountsClient, accountsGraphQL, accountsPassword };