#" Sign in failed. Please try again. " message for " Build & Deploy Social Media App " Tutorial.

114 messages · Page 1 of 1 (latest)

runic shoal
#

One thing that i have noticed is that on his sign up form, there is no error for the const { mutateAsync: signInAccount, isPending, isSigningIn } = useSignInAccount(); but there is for mine, pictures below of what im talking about

#

His:

#

Mine:

#

So maybe the solution lies in figuring out whats wrong with my isPending's and why his isnt a problem but mine is? Im not sure how to fix this tho.

#

Its also possible that wherever or whatever library the isPending comes from has updated their terminology to something different and thats why it isnt correct anymore since the tutorial was made 7 months ago, how could i go about finding this out?

runic shoal
#

Update: i changed
const { mutateAsync: signInAccount, isPending: isSigningIn } = useSignInAccount();
to
const { mutateAsync: signInAccount, isPending: isSigningInUser } = useSignInAccount();
and that fixed the error with isPending, but i still get the same problem when trying to sign up

#

This is the error i get in the console of the website

weary void
weary void
# runic shoal

For this error, it seems to indicate you already have an active session while trying to create a new one. I have not used appwrite myself, but i wonder if it would help to clear cache and cookies to ensure you have killed the session.

runic shoal
runic shoal
weary void
#

I see some similar questions, but they all seem to indicate you need to logout or kill the session.

runic shoal
#

The thing is that for each time i test the signup im also using new information for every cell, so im not sure if it would be a problem with logging out when the account hasnt been created before right?

#

ive also tried to do Ctrl + C in the terminal and then run npm run dev again and that hasnt helped along with clearing cookies and cache and trying again after that too

#

i appreciate you sending the relevant articles, this is my first time ever doing a coding project so im not extremely familiar with fixing things like this, and after taking a look at both the articles i still dont understand what the next steps are that i can take to fix this, do you mind walking me through that please?

weary void
runic shoal
#

like this? do i need to put any information in the () to make the account not have a red underline anymore?

#

im getting an error " Cannot find name 'account'. "

weary void
#

This is the account we are trying to log

runic shoal
#

api.ts:

import { ID, Query } from 'appwrite';

import { INewUser } from "@/types";
import { account, appwriteConfig, avatars, databases } from './config';

export async function createUserAccount(user: INewUser) {
 try {
  const newAccount = await account.create(
    ID.unique(),
    user.email,
    user.password,
    user.name
  );

  if(!newAccount) throw Error;

  const avatarUrl = avatars.getInitials(user.name);

  const newUser = await saveUserToDB({
    accountId: newAccount.$id,
    name: newAccount.name,
    email: newAccount.email,
    username: user.username,
    imageUrl: avatarUrl,
  })

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

export async function saveUserToDB(user: {
  accountId: string;
  email: string;
  name: string;
  imageUrl: URL;
  username?: string;
}) {
  try {
    const newUser = await databases.createDocument(
      appwriteConfig.databaseId,
      appwriteConfig.userCollectionId,
      ID.unique(),
      user,
    )

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

export async function signInAccount(user: { email: string; password: string; }) {
  try {
    const session = await account.createSession(user.email, user.password);

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

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

     if(!currentAccount) throw Error;

     const currentUser = await databases.listDocuments(
      appwriteConfig.databaseId,
      appwriteConfig.userCollectionId,
      [Query.equal('accountId', currentAccount.$id)]
     )

     if(!currentUser) throw Error;

     return currentUser.documents[0];
  } catch (error) {
    console.log(error);
  }
} ```
#

config.ts:


export const appwriteConfig = { 
  url: import.meta.env.VITE_APPWRITE_URL,
  projectId: import.meta.env.VITE_APPWRITE_PROJECT_ID,
  databaseId: import.meta.env.VITE_APPWRITE_DATABASE_ID,
  storageId: import.meta.env.VITE_APPWRITE_STORAGE_ID,
  userCollectionId: import.meta.env.VITE_APPWRITE_USER_COLLECTION_ID,
  postCollectionId: import.meta.env.VITE_APPWRITE_POST_COLLECTION_ID,
  savesCollectionId: import.meta.env.VITE_APPWRITE_SAVES_COLLECTION_ID,
}

export const client = new Client();

client.setProject(appwriteConfig.projectId);
client.setEndpoint(appwriteConfig.url);

export const account = new Account(client);
export const databases = new Databases(client);
export const storage = new Storage(client);
export const avatars = new Avatars(client);
weary void
#

Which function from api was throwing the error you posted? I can edit it to show you how I would debug.

#
export async function createUserAccount(user: INewUser) {
 try {
  const a = account.get(); // Add this line
  console.log(a); // Share this output
  const newAccount = await account.create(
    ID.unique(),
    user.email,
    user.password,
    user.name
  );

  if(!newAccount) throw Error;

  const avatarUrl = avatars.getInitials(user.name);

  const newUser = await saveUserToDB({
    accountId: newAccount.$id,
    name: newAccount.name,
    email: newAccount.email,
    username: user.username,
    imageUrl: avatarUrl,
  })

  return newUser;
 } catch (error) {
  console.log(error);
  return error;
 }
}
runic shoal
#

i believe this is the code block where the error is.

#
      email: values.email,
      password: values.password,
    })

    if(!session) {
      return toast({ title: 'Sign in failed 2. Please try again.'})
    }
#

thank you so much for your help so far

weary void
#
export async function signInAccount(user: { email: string; password: string; }) {
  try {
    const a = account.get(); // Add this line
    console.log(a); // Share this output
    const session = await account.createSession(user.email, user.password);
    return session;
  } catch (error) {
    console.log(error);
  }
}
runic shoal
#

Ive replaced my code with the code that you provided, saved and ran the program again, how do i find the output so i can share that to you?

weary void
#

You can add a string to the log to help search like:

console.log('myUniqueString', log);
runic shoal
#

You know whats weird, is that the information that i see here, isnt the same information i just tried signing up with

weary void
#

Okay so we are getting something back from account.get(). That means that the assumption that a session was already created is true.

#

Do you currently have any logout logic in place?

runic shoal
#

Im unsure, i dont believe so

#

but the info in there is the info from the first ever signup i did

weary void
runic shoal
#

No

#

i dont think so

weary void
#

I saw on appwrite the default session timeout to 1 year. So it seems to me like this user needs to be logged out in order to perform more signups.

runic shoal
#

dang, how can i go about logging out without any logic in my program?

weary void
runic shoal
#

the thing is that in the tutorial so far i dont think thats been implemented, but in the tutorial they never ran into this problem so im wondering why i am

weary void
#

Did they signup multiple users in the tutorial?

#

As I mentioned before, I have never used appwrite, so I def could be missing something.

runic shoal
#

no they didnt i dont think

weary void
#

I would definitely give the CLI a shot then, seems like the best bet.

#

And remember you want to logout the user from that log, not any of the others you have tried to create.

runic shoal
#

what am i doing wrong 😭

weary void
weary void
#

If you installed via npm you might need to run it through npx or an npm script in your package.json.

runic shoal
#

getting this error " cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170. "

runic shoal
#

im sorry for causing all this trouble

weary void
runic shoal
#

that worked

#

kind of

weary void
# runic shoal

Do you have the server actively running? I think npm run dev

runic shoal
#

i didnt

#

but when i do do npm run dev

#

then type npx appwrite login, nothing happens

weary void
runic shoal
#

i didnt have two terminals open sorry

#

but now i did and still get this

#

i dont have any code for sign in yet tho in the tutorial

#

weve only done things for signing up

weary void
#

For the endpoint, could you share your console logs after running npm run dev?

runic shoal
#

yes im signed up and fully set up in appwrite

weary void
runic shoal
#

i didnt realize thats what i was supposed to be logging into here, im sorry one sec

#

i thought this was the app log in

#

will update in 1 min

weary void
#

no worries

runic shoal
#

logged in with Appwrite login info this time ( looks like i used the wrong server info, fixed this in next image )

#

^ progress? 😮

weary void
#

Potentially!

#
export const appwriteConfig = { 
  url: import.meta.env.VITE_APPWRITE_URL,
}

Try this URL?

#

Whatever you have set in your env

#

I think the endpoint in the last screenshot is just the generic appwrite endpoint. My guess is you have a unique one assigned to your when you sign up.

runic shoal
weary void
runic shoal
#

i just tried to do npx appwrite login again and now it didnt even give me the option to enter the endpoint

#

your correct tho, in my env it says https idk why i put http

#

i tried opening a new terminal and it still wont let me try a new endpoint

weary void
#

Hm...

#

Do you happen to have any logs in the other terminal?

#

I am clicking through appwrite a bit more and we could also try doing this from the dashboard.

runic shoal
#

I tried restarting from a backup file and coding to the same point, it seems like there's less errors this time, here is the only problem I'm having right now.

  • 401 (Unauthorized)
  • 400 (Bad Request): AppwriteException: Invalid userId param: Parameter must contain at most 36 chars. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char
#

Do you have any ideas for what could be fixed here? i tried looking up the error codes and saw some solutions but im really not sure how or where to implement them into my own code.

subtle terrace
#

did you ever find out wehat the issue was