What's weird is when I run this part of the code, the response URL triggered is success. which is "http://localhost:5173/".
"auth0",
"http://localhost:5173/",
"http://localhost:5173/error"
);```
When I execute this code below, this is where I'm getting status code 401:
```account
.get()
.then((response) => {
console.log(response); // Success
})
.catch((error) => {
console.log(error); // Failure
});```
Please use 3 backticks to format your code ( ` ) π
Sure, got it..
So, is there any missing implementation on the code I have?
trying to check it
I also notice that when I check the nodemodule/appwrite implementation it is using TypeScript which is not same, since Im using only JSX π
Could you try await
-ing the createOAuth2Session
That shouldn't be an issue
Yes, I did tried also this approach but still same error
What might be happening is that you the code run createOAuth2Session
, and immediately goes to account.get
without waiting for the createOAuth2Session
to finish.
Okay so without the account.get
, it works perfectly?
By the way, I also suspect this thing you mentioned. so another approached I tried is triggering account.get
using function after few seconds createOAuth2Session
Still getting the same issue.
When I also run createOAuth2Session
it refreshes the Page. is this normal ?
which page refreshes? createOAuth2Session
should open a new tab/window to handle the login flow. After which it should take you back to the original page
Sorry, It does not open a new page... It only uses the same page app
That's fair. What you can do is do useEffect
so whenever the page loads, you check if account.get
returns anything. If it does, then go to whichever page. Else run createOAuth2Session
Sure, Let me try this approach
This is the code I just created, and seems to got having the same issue.
useEffect(() => {
// You can await here
const client = new Client()
.setEndpoint("http://20.0.0.150/v1")
.setProject("645a9ddbef60e4b0ecc9");
// setClient(client);
const account = new Account(client);
setAccount(account);
}, []);
const getAccount = async () => {
const hasAccount = await account.get();
hasAccount
.then((response) => {
console.log(response); // Success
})
.catch(() => {
createAuth();
});
};
const createAuth = async () => {
return await account.createOAuth2Session(
"auth0",
"http://localhost:5173",
"http://localhost:5173/error"
);
};```
<button className="m-3" onClick={getAccount}> View Client Credentials </button>
Hi, I tried another option which is using createEmailSession
function (response) {
console.log(response); // Success
},
function (error) {
console.log("Err ", error); // Failure
}
);```
I got this error response:
```{
"message": "Invalid credentials. Please check the email and password.",
"code": 401,
"type": "user_invalid_credentials",
"version": "1.3.4"
}```
Request Payload
{ "email": "email@gmail.com", "password": "password" }```
So, I tried using Postman app to test the request.
Request URL: http://20.0.0.150/v1/account/sessions/email
Request Body: {email: "email@gmail.com", password: "password"}
API request Response:
{"$id":"6472d9d2929b43fab336","$createdAt":"2023-05-28T04:34:27.594+00:00","userId":"645a9dc3ad09e4f03719","expire":"2024-05-27T04:34:26.600+00:00","provider":"email","providerUid":"email@gmail.com","providerAccessToken":"","providerAccessTokenExpiry":"","providerRefreshToken":"","ip":"172.18.0.1","osCode":"","osName":"","osVersion":"","clientType":"library","clientCode":"","clientName":"Postman Desktop","clientVersion":"7.31","clientEngine":"","clientEngineVersion":"","deviceName":"","deviceBrand":"","deviceModel":"","countryCode":"--","countryName":"Unknown","current":true}
Hello, Thank you for assistance, Everything works fine now when Im trying to use the registered users account, which I thought that organizations owner account is the one will authorized the login
[SOLVED] Web SDK - Create Email Session
Recommended threads
- Update User Error
```ts const { users, databases } = await createAdminClient(); const session = await getLoggedInUser(); const user = await users.get(session.$id); if (!use...
- apple exchange code to token
hello guys, im new here π I have created a project and enabled apple oauth, filled all data (client id, key id, p8 file itself etc). I generate oauth code form...
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...