ZeroNP
ZeroNP
SSolidJS
Created by ZeroNP on 7/13/2024 in #support
context provider's values are not being updating after useContext gets user session info.
Using createResource fixed my problems. Thank you! For anyone's future reference, I removing <AuthProvider> and basiclly all the code I had in my context file. The only code I need
const [session, { mutate: updateSession }] = createResource(
async () => {
try {
const session = await account.getSession("current");
if (session) {
const user = await account.get();
return { session, user };
} else {
return null;
}
} catch (error) {
console.log("No active session found");
return null;
}
},
{
initialValue: null,
}
);
export { session, updateSession };
const [session, { mutate: updateSession }] = createResource(
async () => {
try {
const session = await account.getSession("current");
if (session) {
const user = await account.get();
return { session, user };
} else {
return null;
}
} catch (error) {
console.log("No active session found");
return null;
}
},
{
initialValue: null,
}
);
export { session, updateSession };
3 replies