M
Manifest4mo ago
Ian

Token Auth not automatically getting stored as a cookie

How is the login supposed to work? Because when I call loginUser, I get a response with a token but I don't get a cookie back.
loginUser(email, password) {
try {
await manifest.login("users", email, password);
return true;
} catch (error) {
console.error("Login error:", error);
throw new Error("Invalid credentials");
}
}
loginUser(email, password) {
try {
await manifest.login("users", email, password);
return true;
} catch (error) {
console.error("Login error:", error);
throw new Error("Invalid credentials");
}
}
1 Reply
brunobuddy
brunobuddy4mo ago
Hello @Ian After a successful manifest.login() function, the token is automatically attached to the headers of the requests until you manfinest.logout(). This means that you can simply:
await manifest.login('users', 'user@manifest.build', 'passsword') // Log in.

await manifest.from('projects').find() // ✅ Works even if policies are restricted to logged in users.

await manifest.logout() // Empty headers.

await manifest.from('projects').find() // ❌ 403 Error if policies are restricted.
await manifest.login('users', 'user@manifest.build', 'passsword') // Log in.

await manifest.from('projects').find() // ✅ Works even if policies are restricted to logged in users.

await manifest.logout() // Empty headers.

await manifest.from('projects').find() // ❌ 403 Error if policies are restricted.
However if you need the token for some reason (store in local storage for example) , since the SDK version 1.2.2 you can:
const {token} = await manifest.login('users', 'user@manifest.build', 'passsword')
const {token} = await manifest.login('users', 'user@manifest.build', 'passsword')

Did you find this page helpful?