Currently I am login and control what can user see with SSR but I would like to upload files directly to appwrite without upload files first to my server due avoid innecesary traffic. I tried using "{ 'X-Fallback-Cookies': 'my-cookie-name-for-session-token' }" for the headers but I can not receive anything different than 401. Do I have to decide if I want between SSR and SCR? I mean, should I decide if I want my server as middle point between the frontend and backend (appwrite) or use directly the backend?
Is there a way to specify which cookie name should Appwrite use?
I have configured custom domain name but I am testing on localhost.
Set the token from your cookie as the session on your client
const token = cookies.get('cookie');
const client = new Client().setEndpoint().setProject().setSession(token);
You mean inject it into the client side code, right? I though about it but not sure about safety π
But it seems as the only one solution if bandwidth is the top priority π
You'll need a new appwrite client avaliable on the client side if you want to directly upload from the client.
Thank you @Kenny just want to confirm that in case I was missing something in the doc... I was looking like mad person π
im on same boat, according to what i read from here, im doing this:
Php:
// Initialize admin client here
// ...
// Get email and password from request
$email = $_POST['email'];
$password = $_POST['password'];
try {
$account = new Account($adminClient);
// Create the session using the Appwrite client
$session = $account->createEmailPasswordSession($email, $password);
// Set the session cookie
setcookie('session', $session['secret'], [
'httpOnly' => true,
'secure' => true,
'sameSite' => 'strict',
'expires' => strtotime($session['expire']),
'path' => '/',
]);
echo json_encode(['success' => true]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}```
JS (web) part:
```const token = Cookies.get('session');
console.log('Token: ',token);
const client = new Appwrite.Client().setEndpoint(endpoint).setProject('abc').setSession(token);
console.log('Client: ', client);```
Console shows this:
`Token: undefined`
```Client:
config: Object { endpoint: "https://abc.com", endpointRealtime: "wss://abc.com", project: "abc", β¦ }
endpoint: "https://abc.com"
endpointRealtime: "wss://abc.com"
jwt: ""
locale: ""
project: "abc"
ββsession: undefined```
According to what i see, its because the cookie is marked as HttpOnly, and it can only be accessed by the server, not via JavaScript.
So.. do i need to disable the httponly? or is there a better approach to this?
Recommended threads
- The current user is not authorized to pe...
I want to create a document associated with user after log in with OAuth. The user were logged in, but Appwrite said user is unauthorized. User is logged in wi...
- self-hosted auth: /v1/account 404 on saf...
Project created in React/Next.js, Appwrite version 1.6.0. Authentication works in all browsers except Safari (ios), where an attempt to connect to {endpoint}/v1...
- My account is blocked so please check an...
My account is blocked so please unblock my account because all the apps are closed due to which it is causing a lot of problems