How should we handle queries that require a user's password/username? #370
Answered
by
tannerlinsley
transmissions11
asked this question in
General
-
I'm using E2EE encryption for a project I'm working on, and I want to retrieve the user's contacts and decrypt them, and then use ReactQuery to manage refetching, etc. However, I'm not sure if I'm taking the right approach here? import { useQuery } from "react-query";
import { requestAndDecryptUserContacts } from "../api/Users";
import { useAuth } from "../context/UserContext";
const userContactFetcher = async (_, username, decryptionKey) => {
requestAndDecryptUserContacts(username, decryptionKey);
};
export default function useContacts() {
const { decryptionKey, username } = useAuth();
return useQuery(
["contacts", { decryptionKey, username }],
userContactFetcher
);
} It feels odd to have the password + username in the query key? I was wondering if I should make userContactFetcher a closure and use the |
Beta Was this translation helpful? Give feedback.
Answered by
tannerlinsley
Apr 18, 2020
Replies: 1 comment 3 replies
-
How about using the optional queryVariables parameter to send your decryption key through to the query function? import { useQuery } from 'react-query'
import { requestAndDecryptUserContacts } from '../api/Users'
import { useAuth } from '../context/UserContext'
const userContactFetcher = (_, username, decryptionKey) =>
requestAndDecryptUserContacts(username, decryptionKey)
export default function useContacts() {
const { decryptionKey, username } = useAuth()
return useQuery(['contacts', username], decryptionKey, userContactFetcher)
} |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
transmissions11
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
How about using the optional queryVariables parameter to send your decryption key through to the query function?