#" Sign in failed. Please try again. " message for " Build & Deploy Social Media App " Tutorial.
114 messages · Page 1 of 1 (latest)
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?
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
For this you would want to check appwrite docs I believe.
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.
just tried this, it still didnt work sadly.
Ok thank you, im trying to make a post in the appwrite discord support and see if they can help
Are you encountering the AppwriteException "Creation of a session is prohibited when a session is active" in your React Native project? This issue indicates an attempt to log in while already logged in. To address this, ensure you log out before testing the sign-in functionality again. Remember, it's important to manage your sessions appropriate...
I see some similar questions, but they all seem to indicate you need to logout or kill the session.
https://github.com/appwrite/appwrite/discussions/3938#discussioncomment-3746725 Here is another relevant discussion
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?
I personally would need to do some more debugging. It sounds like account.get() will return if a session is active. So I would try calling that on the line before the code that throws the error above. See if that does in fact contain a session and maybe any useful info about it.
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'. "
Not quite, can you share the code where you init the appwrite client?
This is the account we are trying to log
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);
So this is the account we are looking for.
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;
}
}
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
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);
}
}
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?
Check the browser console and your terminal, you should see a log
You can add a string to the log to help search like:
console.log('myUniqueString', log);
You know whats weird, is that the information that i see here, isnt the same information i just tried signing up with
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?
Im unsure, i dont believe so
but the info in there is the info from the first ever signup i did
Has singup ever worked since then?
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.
dang, how can i go about logging out without any logic in my program?
https://appwrite.io/docs/tooling/command-line/commands I would try the appwrite CLI
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
Did they signup multiple users in the tutorial?
As I mentioned before, I have never used appwrite, so I def could be missing something.
no they didnt i dont think
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.

What installation method did you use for the CLI?
https://appwrite.io/docs/tooling/command-line/installation#install-with-script I think this would be the best option, rather than via npm
If you installed via npm you might need to run it through npx or an npm script in your package.json.
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. "
how would i run it through npx or an npm script in package.json?
im sorry for causing all this trouble
Try this,
npm install appwrite-cli # do this from the root of your project
npx appwrite login
Do you have the server actively running? I think npm run dev
i didnt
but when i do do npm run dev
then type npx appwrite login, nothing happens
Can you screenshot? Make sure you have two terminals open
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
But did you sign up for Appwrite before starting this? That is what you should be logging in as
For the endpoint, could you share your console logs after running npm run dev?
yes im signed up and fully set up in appwrite
Are you using that same email and password in the CLI?
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
no worries
logged in with Appwrite login info this time ( looks like i used the wrong server info, fixed this in next image )
^ progress? 😮
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.
i used the one from my ENV in this one
try https on that
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
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.
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
userIdparam: 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.
did you ever find out wehat the issue was