How to create specific URIs for users in FIREBASE WEB javascript

青春壹個敷衍的年華 提交于 2021-02-05 12:07:16

问题


I have a firebase project developed in javscript html and css that works like a social network, i have users in my database and these users have profile information to show.

The problem is, i want to associate each user to a specific URI so everyone can use that link to access a user's info.

Example:

I want to generate a link for users like "https://myproject.com/users/john-doe" (for user john doe) and i want it to bring to that specific user page.

I'm using firebase hosting and there is something for rewriting urls but i couldn't see anything to suit my case, its the intire week i-m looking to solve this problem and still haven't found something yet, please help, thank you!


回答1:


What you're describing is a single-page application, where a single HTML+JavaScript page is handling many URLS - dynamically generating the content.

You'll need to implement multiple steps:

  1. Configure Firebase Hosting to direct multiple incoming URLs to the same HTML page. This is done with a rewrite rule in your firebase.json file, such as:

    "rewrites": [ {
      "source": "**",
      "destination": "/index.html"
    } ]
    
  2. Now the JavaScript of your index.html page can inspect the URL in window.location.href, extract the user name from it, and then serve the correct content for that user.



来源:https://stackoverflow.com/questions/64077469/how-to-create-specific-uris-for-users-in-firebase-web-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!