--- title: "Adding a Rocket.Chat Room to Your Web App" slug: "adding-a-rocketchat-chat-room-to-your-web-app" description: "Embed a Rocket Chat room in your web app. Enable secure communication, boost collaboration, and improve user engagement." updated: 2026-02-09T08:37:45Z published: 2026-02-09T08:37:45Z canonical: "developer.rocket.chat/adding-a-rocketchat-chat-room-to-your-web-app" --- > ## Documentation Index > Fetch the complete documentation index at: https://developer.rocket.chat/llms.txt > Use this file to discover all available pages before exploring further. # Adding a Rocket.Chat Room to Your Web App After [configuring iframe auth](/v1/docs/configuring-iframe-auth), you can explore and customize Rocket.Chat. Iframe integration in Rocket.Chat allows you to embed chat rooms from your Rocket.Chat server on other websites or web apps. ## Prerequisites - A running Rocket.Chat server with at least one room. > [!NOTE] > See the [official deployment guide](https://docs.rocket.chat/v1/docs/deploy-rocketchat) to explore various ways of setting up your Rocket.Chat workspace. ## Activate the iframe integration To enable the Iframe integration setting in your Rocket.Chat workspace, - Navigate to **Manage**  **> Workspace > Settings > Accounts > Iframe**. - Toggle **on** the **Enabled** option. - Fill in the **iframe URL** with the application URL where you want to integrate the current Rocket.Chat application. - Add the **API URL**, which is essential for Rocket.Chat to verify that a user is logged into the application. If a user in your application visits a web page containing the Rocket.Chat room iframe, the Rocket.Chat server will use this API endpoint to verify the following: - The user is identified on your web app. - The credentials provided are used to attempt a login to the Rocket.Chat server. - Click **Save Changes**. > [!NOTE] > This demo sample uses `http://localhost:3030/` and assumes the application is running on port `3000`. - Navigate to **Manage**  **> Workspace > Settings > General**. - Disable **Restrict access inside any Iframe**. > [!WARNING] > Disabling this feature is a security hole in your Rocket.Chat server. It allows anyone to load the iframe from your server into their app. Enabling it allows only your application's URL to use the iframe. - Click **Save Changes**. ## Iframe authentication For authentication, there are two possibilities: - The user already has a Rocket.Chat account - The user does not have a Rocket.Chat account It is essential to know how to manage these cases to ensure Rocket.Chat can identify the user of the iframe. > [!NOTE] > You can test iframe authentication with our [sample demo on GitHub](https://github.com/RocketChat/iframe-auth-example). ### [](/docs/adding-a-rocketchat-chat-room-to-your-web-app#set-up-and-use-the-demo-code)Set up and use the demo code - Clone the [GitHub repository](https://github.com/RocketChat/iframe-auth-example). ```bash git clone https://github.com/RocketChat/iframe-auth-example.git ``` - Navigate to the cloned directory and open it in your IDE. ```bash cd iframe-auth-examples ``` - Install the demo packages. ```bash npm install ``` > [!CAUTION] > Do not launch the demo app directly now; you still need to make some modifications. ### [](/docs/adding-a-rocketchat-chat-room-to-your-web-app#modifying-the-demo-code)Modifying the demo code Before using the demo code, there are still some modifications to do. - Update the `index.js` file with this code: ```javascript // var express = require('express'); var bodyParser = require('body-parser'); var axios = require('axios'); var fs = require('fs'); var app = express(); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); // CORS in case you need app.use((req, res, next) => { res.set('Access-Control-Allow-Origin', 'http://localhost:3000'); // this is the rocket.chat URL res.set('Access-Control-Allow-Credentials', 'true'); next(); }); // this is the endpoint configured as API URL app.post('/sso', function (req, res) { // add your own app logic here to validate user session (check cookies, headers, etc) // if the user is not already logged in on your system, respond with a 401 status var notLoggedIn = false; if (notLoggedIn) { return res.sendStatus(401); } // you can save the token on your database as well, if so just return it // MongoDB - services.iframe.token var savedToken = null; if (savedToken) { return res.json({ token: savedToken, }); } // if dont have the user created on rocket.chat end yet, you can now create it var currentUsername = true; if (!currentUsername) { axios .post('http://localhost:3000/api/v1/users.register', { username: 'new-user', email: 'mynewuser@email.com', pass: 'new-users-passw0rd', name: 'New User', }) .then(function (response) { // after creation you need to log the user in to get the `authToken` if (response.data.success) { return axios.post('http://localhost:3000/api/v1/login', { username: 'new-user', password: 'new-users-passw0rd', }); } }) .then(function (response) { if (response.data.status === 'success') { res.json({ loginToken: response.data.data.authToken, }); } }) .catch(function (error) { res.sendStatus(401); }); } else { // otherwise create a rocket.chat session using rocket.chat's API axios .post('http://localhost:3000/api/v1/login', { username: 'new-user', password: 'new-users-passw0rd', }) .then(function (response) { if (response.data.status === 'success') { res.json({ loginToken: response.data.data.authToken, }); } }) .catch(function () { res.sendStatus(401); }); } }); // just render the form for the user authenticate with us app.get('/login', function (req, res) { res.set('Content-Type', 'text/html'); fs.createReadStream('login.html').pipe(res); }); app.get('/home', function (req, res) { res.set('Content-Type', 'text/html'); fs.createReadStream('home.html').pipe(res); }); // receives login information app.post('/login', function (req, res) { // do your own authentication process // after the user is authenticated we can proceed with authenticating him on rocket.chat side // // // the code below is exactly the same as the on /sso endpoint, except for its response // it was duplicated for understanding purpose // the authentication process and is a well-designed app =) // // // if dont have the user created on rocket.chat end yet, you can now create it var currentUsername = null; if (!currentUsername) { axios .post('http://localhost:3000/api/v1/users.register', { username: 'new-user', email: 'mynewuser@email.com', pass: 'new-users-passw0rd', name: 'New User', }) .then(function (response) { // after creation you need to log the user in to get the `authToken` if (response.data.success) { return axios.post('http://localhost:3000/api/v1/login', { username: 'new-user', password: 'new-users-passw0rd', }); } }) .then(function (response) { if (response.data.status === 'success') { res.redirect('/home'); } }) .catch(function (error) { res.sendStatus(401); }); } else { // otherwise create a rocket.chat session using rocket.chat's API axios .post('http://localhost:3000/api/v1/login', { username: 'username-set-previously', password: 'password-set-previously', }) .then(function (response) { if (response.data.status === 'success') { // since this endpoint is loaded within the iframe, we need to communicate back to rocket.chat using `postMessage` API res.set('Content-Type', 'text/html'); res.send( `` ); } }) .catch(function () { res.sendStatus(401); }); } }); app.listen(3030, function () { console.log('Example app listening on port 3030!'); }); ``` - Create a new file called `home.html` in the root directory. Update the file with this code: ```xml //