
I am getting this error when I am trying to see if a User is currently logged into a session. I am using Next14 with Typescript.
I am using client-side functions for both the Account creation and the SignUp page. (If the user is signed in already and goes to sign up, it should just route them to their account page.)
// inside of my SignUp page.tsx
const getSession = () => {
// this is where the error is getting thrown
account.get().then((res) => {
setSession(res);
}).catch((e) => {
console.log(e);
})
}
useEffect(() => {
getSession();
if (session) {
router.push("/my-account")
}
}, []);
I am a little confused on how the account/user scopes work when youre trying to check for a logged in user that is not logged in?

Please don't tag people as it can be disruptive. Please just wait

apologies!

async function init() {
try {
const loggedIn = await account.get();
setUser(loggedIn);
} catch (err) {
setUser(null);
}
}

according to the own docs, you just catch the error and set the user to null if there is an error?

strange

No worries!

const [user, setUser] = useState<Models.User<Models.Preferences> | null>(null);
const [session, setSession] = useState<Models.Session>();
const router = useRouter();
const handleSignUp = () => {
setLoading(true);
signUp(email, password).then((res) => {
setError("");
setLoading(false);
account.createEmailPasswordSession(email, password).then((sesh) => {
setSession(sesh);
})
router.push("/my-account")
}).catch((e: AppwriteException) => {
setError(e.message);
setLoading(false);
});
}
const getUser = async () => {
getAccount().then((res) => {
setUser(res);
}).catch((e) => {
setUser(null);
})
}
useEffect(() => {
getUser().then(() => {
if (user) {
router.push("/my-account");
}
});
}, [user]);

for anyone who comes against this problem in the future, this seems to work

i cant say as to why the design works like this

const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const [session, setSession] = useState<Models.Session>();
const router = useRouter();
const handleSignUp = () => {
setLoading(true);
signUp(email, password).then((res) => {
setError("");
setLoading(false);
account.createEmailPasswordSession(email, password).then((sesh) => {
setSession(sesh);
})
router.push("/my-account");
}).catch((e: AppwriteException) => {
setError(e.message);
setLoading(false);
});
}
useEffect(() => {
getAccount().then((res) => {
router.push('/my-account')
}).catch((e) => {
// do nothing
});
}, []);

Even shorter version
Recommended threads
- Subdomain failed verification
So I wanted to do a custom subdomain, because local storage doesn't work for me, but I've tried it a long time ago, it didn't work for me, and now I'm trying ag...
- [Node.js SDK] Bypass 2GB file limit?
Hello. Using either InputFile.fromPath or InputFile.fromBuffer throws this error: File size (2295467305) is greater than 2 GiB Bucket limit etc. is setup corre...
- Relationship null, even when relationshi...
Hi Everyone, im experiencing issues with set relation data. When im setting the document id from the related database most of them seem fine, except one table. ...
