I’m new to Medusajs and I’m trying to integrate Firebase into Medusajs in order to add a register/login with a phone number in my Medusa app following Medusajs docs on how to create a custom endpoint here. Below is my current approach and the error I’m getting while trying to implement it.
First of all, I’ve created a folder called “config” within the “src” folder. Inside config, I’ve created a “firebaseConfig.js” file that contains firebase config as the name explains(Firebase -v 10.12.2).
firebaseConfig:
import { initializeApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';
const firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "s",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
// Get a reference to the Auth service
export const auth = getAuth(app);
Secondly, inside “src/api/store” I’ve created my endpoint in the following path, “auth/register/route.ts. So the final path to my endpoint inside Medusa’s backend folder is “src/api/store/auth/register/route.ts”
The route.ts:
import { Router } from 'express';
import { getAuth, PhoneAuthProvider } from 'firebase/auth';
const route = Router();
route.post('/store/auth/register', async (req, res) => {
const { phoneNumber, recaptchaToken } = req.body;
const auth = getAuth();
try {
// Assuming recaptchaToken is already verified on client-side
const phoneProvider = new PhoneAuthProvider(auth);
const verificationId = await phoneProvider.verifyPhoneNumber(phoneNumber, recaptchaToken);
// Send the verificationId back to the client
res.status(200).send({ verificationId });
} catch (error) {
res.status(500).send(error.message);
}
});
export default route;
The third step I made is that I created a file called “routes.ts” inside “src/api/store” that contains the following code:
import { Express } from 'express';
import authRoutes from './auth/register/route';
const storeRoutes = (app: Express) => {
app.use('/store', authRoutes);
};
export default storeRoutes;
After that, I ran the command “npm run build” and it built the project correctly. The final step is that I ran the command “medusa develop”, and here where comes the issue. The terminal displays the following error:
error: Error starting server
TypeError: Cannot read properties of undefined (reading 'use')
at storeRoutes (C:UsersEast-SoundDesktopProjectsfourpets-backenddistapistoreroutes.js:8:9)
Finally, I’m kind of lost here. I don’t know if my approach is correct, and if not what is a correct approach. In case my approach is correct, what is wrong with my logic and how would I solve this issue? I’d really appreciate it if someone could help me.