Giter Site home page Giter Site logo

Comments (48)

Aashish1009 avatar Aashish1009 commented on August 17, 2024 1

im also getting same issue

from social_media_app.

Proj-Valentine avatar Proj-Valentine commented on August 17, 2024 1

I am getting the same issue too, cant connect with appwrite

from social_media_app.

Proj-Valentine avatar Proj-Valentine commented on August 17, 2024 1

When the code in the file config.ts executes this line const currentAccount = await account.get() it does not connect to Appwrite, in the console shows this:

image Does anyone have the same issue?

did you get the issue resolved?

from social_media_app.

Proj-Valentine avatar Proj-Valentine commented on August 17, 2024 1

Yes, I ran into this issue.

I solved it by starting a (1) "web" client, and (2) changing hostname to *

Screenshot 2023-11-02 191737

Can step by step run through what you did for it to work?

from social_media_app.

IasmimCristina avatar IasmimCristina commented on August 17, 2024 1

@IasmimCristina , Can u please try replacing the
appwriteConfig.databaseId and appwriteConfig.useCollectionId
with the values of those in quotes

image

Hello!

I have done that, actually, my code was like that but I changed it when I made that screenshot.
(And it was with the double quotes 😒)

The difference it makes is that when the sign in page loads it doesn't get the unauthorized error message.

However, when I reload the page the session doesn't persist still and when I logout I get the unauthorized error message again.

from social_media_app.

Rondev9 avatar Rondev9 commented on August 17, 2024 1

@IasmimCristina , Can u please try replacing the
appwriteConfig.databaseId and appwriteConfig.useCollectionId
with the values of those in quotes

image

Hello!

I have done that, actually, my code was like that but I changed it when I made that screenshot.
(And it was with the double quotes 😒)

The difference it makes is that when the sign in page loads it doesn't get the unauthorized error message.

However, when I reload the page the session doesn't persist still and when I logout I get the unauthorized error message again.

Hey @IasmimCristina, If you don't mind, can you please invite me to your project repo, I'll do my best to resolve the issue.

from social_media_app.

Rondev9 avatar Rondev9 commented on August 17, 2024 1

"Fantastic @Onunkwor! πŸŽ‰ I'm glad to hear that you resolved the issue. It's always those little details that can make a big difference. Kudos! Also, great catch on fixing the getCurrentUser functionβ€”consistent casing is key. If you run into any more challenges or have questions in the future, feel free to reach out. Happy coding! πŸ‘©β€πŸ’»πŸš€"

from social_media_app.

Rondev9 avatar Rondev9 commented on August 17, 2024 1

@Rondev9 , thank you very much, I invited you just now.

hey! were you able to resolve the issue? i have been facing the same problem for a few hours now and have been unable to tackle it

Hey @siya-pathak, Yeah I'm able to resolve it.

hi could you tell me how did you? i did refer to [https://github.com//issues/19#issuecomment-1807460381](this comment here) and the sign-up is working fine now after making this modification, but i just wanted to know any other way this could be solved :)

You can use local storage to save the user ID, so that it won't complain about the 401 as we're using the user id from local storage whenever we make a call to AppWrite. So why we're using local storage here, overtime AppWrite fails to fetch the user id from AppWrite's session, which results in 401. And don't forget to clear the local storage on sign out.

from social_media_app.

siya-pathak avatar siya-pathak commented on August 17, 2024 1

@Rondev9 , thank you very much, I invited you just now.

hey! were you able to resolve the issue? i have been facing the same problem for a few hours now and have been unable to tackle it

Hey @siya-pathak, Yeah I'm able to resolve it.

hi could you tell me how did you? i did refer to [https://github.com//issues/19#issuecomment-1807460381](this comment here) and the sign-up is working fine now after making this modification, but i just wanted to know any other way this could be solved :)

You can use local storage to save the user ID, so that it won't complain about the 401 as we're using the user id from local storage whenever we make a call to AppWrite. So why we're using local storage here, overtime AppWrite fails to fetch the user id from AppWrite's session, which results in 401. And don't forget to clear the local storage on sign out.

thank you so much for this :)

from social_media_app.

hmongdev avatar hmongdev commented on August 17, 2024

Yes, I ran into this issue.

I solved it by starting a
(1) "web" client, and
(2) changing hostname to *

Screenshot 2023-11-02 191737

from social_media_app.

ludwing979 avatar ludwing979 commented on August 17, 2024

I tried that but still is not working, I also tried to delete the project and create a new one but still is giving me the same error

from social_media_app.

hmongdev avatar hmongdev commented on August 17, 2024

I tried that but still is not working, I also tried to delete the project and create a new one but still is giving me the same error

If your code is 100% correct, it has to be appwrite.

Make sure you set up your auth and database correctly. That's the best advice I can give without looking at your code.

from social_media_app.

hmongdev avatar hmongdev commented on August 17, 2024

I tried that but still is not working, I also tried to delete the project and create a new one but still is giving me the same error

Sorry I haven't had time to write a proper response, but @Rondev9 created it here. These are the steps you must take: #3 (comment)

from social_media_app.

hmongdev avatar hmongdev commented on August 17, 2024

Sorry I haven't had time to write a proper response, but @Rondev9 created it here. These are the steps you must take: #3 (comment)

from social_media_app.

hmongdev avatar hmongdev commented on August 17, 2024

I tried that but still is not working, I also tried to delete the project and create a new one but still is giving me the same error

Sorry I haven't had time to write a proper response, but @Rondev9 created it here. These are the steps you must take: #3 (comment)

from social_media_app.

athskouroliakos avatar athskouroliakos commented on August 17, 2024

I am dealing with the same issue and creating a web platform did not fix it.

from social_media_app.

ludwing979 avatar ludwing979 commented on August 17, 2024

When the code in the file config.ts executes this line const currentAccount = await account.get() it does not connect to Appwrite, in the console shows this:
image
Does anyone have the same issue?

did you get the issue resolved?

No, I search for different solutions but I still can't figure it out

from social_media_app.

Rondev9 avatar Rondev9 commented on August 17, 2024

When the code in the file config.ts executes this line const currentAccount = await account.get() it does not connect to Appwrite, in the console shows this:
image
Does anyone have the same issue?

did you get the issue resolved?

No, I search for different solutions but I still can't figure it out

Hey @ludwing979 in order to tackle with the 401, I'm using local storage to store the userId (as a bruteforce method) and on sign out I'm clearing the local storage to delete the current user session.
Here's the reference:

Sign-in:

export async function signInAccount(user: { email: string; password: string }) {
  try {
    const session = await account.createEmailSession(user.email, user.password);
    localStorage.setItem("sessionId", session.userId); //userId stored as a sessionId -> purpose of storing is after some time of user log in, when try to fetch useId on reload the appWrite is unable to fetch resulting 401
    return session;
  } catch (error) {
    console.log(error);
  }
}

Sign-out:

export async function signOutAccount() {
  try {
    localStorage.clear();
    const session = await account.deleteSession("current");
    return session;
  } catch (error) {
    console.log(error);
  }
}

Hope it helps 😊

from social_media_app.

athskouroliakos avatar athskouroliakos commented on August 17, 2024

When the code in the file config.ts executes this line const currentAccount = await account.get() it does not connect to Appwrite, in the console shows this:
image
Does anyone have the same issue?

did you get the issue resolved?

No, I search for different solutions but I still can't figure it out

Hey @ludwing979 in order to tackle with the 401, I'm using local storage to store the userId (as a bruteforce method) and on sign out I'm clearing the local storage to delete the current user session. Here's the reference:

Sign-in:

export async function signInAccount(user: { email: string; password: string }) {
  try {
    const session = await account.createEmailSession(user.email, user.password);
    localStorage.setItem("sessionId", session.userId); //userId stored as a sessionId -> purpose of storing is after some time of user log in, when try to fetch useId on reload the appWrite is unable to fetch resulting 401
    return session;
  } catch (error) {
    console.log(error);
  }
}

Sign-out:

export async function signOutAccount() {
  try {
    localStorage.clear();
    const session = await account.deleteSession("current");
    return session;
  } catch (error) {
    console.log(error);
  }
}

Hope it helps 😊

I tried that but the issue remains, the problem as shown in the screenshot seems to be at the getCurrentUser.

apprwrite_401

from social_media_app.

Rondev9 avatar Rondev9 commented on August 17, 2024

Hey @athskouroliakos, If it's acceptable to you, kindly add me to your repository. This will allow me to thoroughly study the code, and I assure you that I will contribute towards resolving the error.

from social_media_app.

ludwing979 avatar ludwing979 commented on August 17, 2024

@Rondev9 Can I also add you to my repository to check, I have the same problem as @athskouroliakos

from social_media_app.

Rondev9 avatar Rondev9 commented on August 17, 2024

@Rondev9 Can I also add you to my repository to check, I have the same problem as @athskouroliakos

Sure @ludwing979! Please go ahead.

from social_media_app.

IasmimCristina avatar IasmimCristina commented on August 17, 2024

Were you able to fix it? @athskouroliakos @Rondev9 , I'm facing the same issue.

from social_media_app.

TheerthA88 avatar TheerthA88 commented on August 17, 2024

Were you able to fix it? @athskouroliakos @Rondev9 , I'm facing the same issue.

@IasmimCristina, can you pls share the screenshots if you don't mind

from social_media_app.

IasmimCristina avatar IasmimCristina commented on August 17, 2024

Here they are:
Im basically receiving the same error as the author of the issue, I've already added the Web platform, and re-made the project in appwrite and checked JSM's code. Weirdly, yesterday it was working fine, but now when I re-load the page the session doesnt work.

Captura de tela de 2023-11-24 17-25-17
The local storage message appears once I login and the first ones as soon as the app loads the signin page.
Captura de tela de 2023-11-24 17-25-36
Here are the functions and console ninja error messages, the same mentioned:
Captura de tela de 2023-11-24 17-17-32
The unathourized error is refering to this line:
const currentAccount = await account.get();

Captura de tela de 2023-11-24 17-24-08

from social_media_app.

TheerthA88 avatar TheerthA88 commented on August 17, 2024

@IasmimCristina , Can u please try replacing the
appwriteConfig.databaseId and appwriteConfig.useCollectionId
with the values of those in quotes

image

from social_media_app.

IasmimCristina avatar IasmimCristina commented on August 17, 2024

@Rondev9 , thank you very much, I invited you just now.

from social_media_app.

Onunkwor avatar Onunkwor commented on August 17, 2024

I'm having a 401 authorization issue when I try to sign up or sign in. The users are correctly added to app write and the local storage but the page doesn't redirect and I have these issues @Rondev9

Screenshot 2023-12-06 225449

from social_media_app.

Rondev9 avatar Rondev9 commented on August 17, 2024

I'm having a 401 authorization issue when I try to sign up or sign in. The users are correctly added to app write and the local storage but the page doesn't redirect and I have these issues @Rondev9

Screenshot 2023-12-06 225449

Hey @Onunkwor, invite me to your project, So that I can understand more about the issue.

from social_media_app.

Onunkwor avatar Onunkwor commented on August 17, 2024

@Rondev9 Good morning I've done that

from social_media_app.

Onunkwor avatar Onunkwor commented on August 17, 2024

Thank you @Rondev9 I found a solution to it. I added permission to the saveToDb function which worked. I also faced an invalid query error in the getCurrentUser function cos I used [Query.equal("accountId", currentAccount.$id)] instead of [Query.equal("accountID", currentAccount.$id)] because when saving the user to the database I used accountID
Screenshot 2023-12-07 190927
Screenshot 2023-12-07 204951

from social_media_app.

sridhar-pro avatar sridhar-pro commented on August 17, 2024

@Onunkwor @Rondev9
I updated the code but still getting same error
can you help me to fix this

Screenshot 2023-12-09 121236

Screenshot 2023-12-09 121250

Screenshot 2023-12-09 121305

from social_media_app.

Onunkwor avatar Onunkwor commented on August 17, 2024

@sridhar-pro Good morning, Are you using .env or .env.local for your API keys?

from social_media_app.

sridhar-pro avatar sridhar-pro commented on August 17, 2024

@Onunkwor i'am using .env.local for the API keys

from social_media_app.

Onunkwor avatar Onunkwor commented on August 17, 2024

@sridhar-pro Sorry about the late reply; I've been caught up with schoolwork. I encountered an error where the API keys were not accessed properly when I used .env.local, so I switched to just .env, and it worked fine.

from social_media_app.

sridhar-pro avatar sridhar-pro commented on August 17, 2024

@Onunkwor thank you brother it's worked

from social_media_app.

Onunkwor avatar Onunkwor commented on August 17, 2024

@sridhar-pro you're welcome

from social_media_app.

siya-pathak avatar siya-pathak commented on August 17, 2024

@Rondev9 , thank you very much, I invited you just now.

hey! were you able to resolve the issue? i have been facing the same problem for a few hours now and have been unable to tackle it

from social_media_app.

Rondev9 avatar Rondev9 commented on August 17, 2024

@Rondev9 , thank you very much, I invited you just now.

hey! were you able to resolve the issue? i have been facing the same problem for a few hours now and have been unable to tackle it

Hey @siya-pathak, Yeah I'm able to resolve it.

from social_media_app.

siya-pathak avatar siya-pathak commented on August 17, 2024

@Rondev9 , thank you very much, I invited you just now.

hey! were you able to resolve the issue? i have been facing the same problem for a few hours now and have been unable to tackle it

Hey @siya-pathak, Yeah I'm able to resolve it.

hi could you tell me how did you? i did refer to [https://github.com//issues/19#issuecomment-1807460381](this comment here) and the sign-up is working fine now after making this modification, but i just wanted to know any other way this could be solved :)

from social_media_app.

Rondev9 avatar Rondev9 commented on August 17, 2024

@Rondev9 , thank you very much, I invited you just now.

hey! were you able to resolve the issue? i have been facing the same problem for a few hours now and have been unable to tackle it

Hey @siya-pathak, Yeah I'm able to resolve it.

hi could you tell me how did you? i did refer to [https://github.com//issues/19#issuecomment-1807460381](this comment here) and the sign-up is working fine now after making this modification, but i just wanted to know any other way this could be solved :)

You can use local storage to save the user ID, so that it won't complain about the 401 as we're using the user id from local storage whenever we make a call to AppWrite. So why we're using local storage here, overtime AppWrite fails to fetch the user id from AppWrite's session, which results in 401. And don't forget to clear the local storage on sign out.

thank you so much for this :)

You're welcome @siya-pathak. Happy coding πŸš€πŸš€

from social_media_app.

ToufikGouri avatar ToufikGouri commented on August 17, 2024

When i am creating a new user, even it gets stored in my DB of appwrite, then still it can't get updated in my redux store, the login and logout is working fine only the Signup is creating problem
Please help me anybody

my userdetails slice looks like this
export const userDetails = createAsyncThunk('userDetails', async () => {
try {
const getData = await account.get()
return getData;
} catch (error) {
return 0
}
})
worked fine with login and logout just problem with the Signup

Sign up function :
e.preventDefault()

    const promise = account.create(
        uuidv4(),
        user.email,
        user.password,
        user.name
    );

    promise.then(
        function (response) {
            console.log(response);
            if (response) {
                dispatch(userDetails()); // Dispatch userDetails action to update the Redux state
            }
            navigate("/")   //Success
        },
        function (error) {
            console.log(error);    //Failed
        }
    )

}


please help meeee

from social_media_app.

rahulAgdev avatar rahulAgdev commented on August 17, 2024

I faced the same issue, it is because account.get() will not return the current account immediately, which throws the execution to the catch block. And hence you are receiving this error.

To solve this error, I created a separate function to get the current user using the account.get function and then call it inside the getCurrentUser function ( if that is what you have named it )

export async function getAccount() {
  try {
    const currentAccount = await account.get();

    return currentAccount;
  } catch (error) {
    console.log(error);
  }
}

then use this getAccount function to fetch your user account details in your main function.

from social_media_app.

ToufikGouri avatar ToufikGouri commented on August 17, 2024

I faced the same issue, it is because account.get() will not return the current account immediately, which throws the execution to the catch block. And hence you are receiving this error.

To solve this error, I created a separate function to get the current user using the account.get function and then call it inside the getCurrentUser function ( if that is what you have named it )

export async function getAccount() {
  try {
    const currentAccount = await account.get();

    return currentAccount;
  } catch (error) {
    console.log(error);
  }
}

then use this getAccount function to fetch your user account details in your main function.

But bro as you can see in my starting line of response the code is same as like yours, I used the async await to get user in seperate function :(

from social_media_app.

rahulAgdev avatar rahulAgdev commented on August 17, 2024

I faced the same issue, it is because account.get() will not return the current account immediately, which throws the execution to the catch block. And hence you are receiving this error.

To solve this error, I created a separate function to get the current user using the account.get function and then call it inside the getCurrentUser function ( if that is what you have named it )

export async function getAccount() {
  try {
    const currentAccount = await account.get();

    return currentAccount;
  } catch (error) {
    console.log(error);
  }
}

then use this getAccount function to fetch your user account details in your main function.

But bro as you can see in my starting line of response the code is same as like yours, I used the async await to get user in seperate function :(

Can you try to call the account.create() function seperately and call it again by returning from another function and try. If this doesn't work, let's connect and debug this together

from social_media_app.

bizrockman avatar bizrockman commented on August 17, 2024

I debugged it a little bit further. Actually this error makes complete sense. And it is not a bug like it was mentioned in the video.

It behaves like intended. You are not logged in so you go to sign-in. As soon as you comment out cookieFallback === null, the method checkAuthUser() is called, but since you are guest (not a logged In user) you do not have an account. So this error occurs.

How this is setup up you will never see the sign-up page.

Now change the line in useEffect to /sign-up.

After you sign-up you will automatically logged In and after you will not get that error any longer.

I did not through with the video, So I do not know how the pageflow will be. But I think that you need some expections while checking the user. If you are not logged In I would redirect you to sign-up. If you click on sign-in you need a further check in useEffect, to ensure that the user stays on sign-in without gettting redirected to sign-up again.

And then you are done ;-)

from social_media_app.

bizrockman avatar bizrockman commented on August 17, 2024

Ok, I have managed it to work correctly with an easy fix:

`const [isAuthenticated, setIsAuthenticated] = useState(false)

const navigate = useNavigate()
const location = useLocation()

const checkAuthUser = async () => {
    setIsLoading(true)
    try {

`

Add const location = userLocation()

and use it in the useEffect Method

` useEffect(() => {
const cookieFallback = localStorage.getItem("cookieFallback");
if (
cookieFallback === "[]" ||
cookieFallback === null ||
cookieFallback === undefined
) {
if (location.pathname === "/sign-in") {
navigate("/sign-in");
} else {
navigate("/sign-up");
}
}

    checkAuthUser();        
  }, []);

`

Now the app is working as expected without the 401 Unauthorized User guest as not account exception

from social_media_app.

captaincharan avatar captaincharan commented on August 17, 2024

@Rondev9 Please help me I am struggling with he issue

from social_media_app.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.