telegram-auth-example icon indicating copy to clipboard operation
telegram-auth-example copied to clipboard

Support

Open CyberBishop opened this issue 1 year ago • 0 comments

Hey please I need your help

This generate session and sets the cookie on the frontend

app.get("/generate-session", (req, res) => {
	const sessionId = req.sessionID;

	req.session.save((err) => {
		if (err) {
			console.error("Error saving session:", err);
			return res
				.status(500)
				.json({ success: false, error: "Failed to save session" });
		}

		res.cookie("sessionId", req.sessionID, {
			httpOnly: false,
			secure: true,
			sameSite: "None",
		});

		return res.status(200).json({ success: true, sessionId });
	});
});

When the user clicks start after using the t.me link, this happens

bot.onText(/\/start (.+)/, async (msg, match) => {
	const { chat, from } = msg;
	const chatId = chat.id;
	const sessionId = match[1];

	const sessionData = await getSessionData(sessionId);

	if (sessionData) {
		const { id, first_name, last_name, username } = from;

		const newSessionData = await mongoose.connection
			.collection("sessions")
			.updateOne(
				{ _id: sessionId },
				{ $set: { chatId: id, username, first_name, last_name } }
			);

		const responseMessage = `Welcome, ${username}! You are now logged in.`;
		bot.sendMessage(chatId, responseMessage);
	} else {
		const responseMessage = "Invalid session ID. Please log in again.";
		bot.sendMessage(chatId, responseMessage);
	}
});

my question is after now I do I respond to the website that login was successful

CyberBishop avatar Jul 19 '23 11:07 CyberBishop