项目作者: rslvn

项目描述 :
Firebase full password authentication (register, login, forget password, reset password), google/twitter/facebook authentication
高级语言: Vue
项目地址: git://github.com/rslvn/nuxt-typescript-ssr-firebase-auth.git
创建时间: 2020-04-25T01:33:23Z
项目社区:https://github.com/rslvn/nuxt-typescript-ssr-firebase-auth

开源协议:

下载


nuxt-typescript-ssr-firebase-auth

BUILD
Coverage Code
Lines Of Code
Technical Debit

nuxt generate is really sucks!!! We lost nuxtServerInit, dynamic routing stuff etc. We need a good alternative to deploy our applications to the cloud without VPS and SSL configuration.

This repository is created as a sample of using nuxt on firebase-functions+firebase-hosting and still SSR and has the nuxtServerInit functionality as active.

Firebase full password authentication (register, login, forget password, reset password), google authentication, twitter authentication, facebook authentication in nuxt.

DEMO: https://nuxt-ts-firebase-auth-ssr.firebaseapp.com/

See the Features for more functionalities

Profile Ligthbox Ligthbox view
Crop login register

Folder Structure

  • functions: source folder for firebase-functions
    • modules: Shared types and functions between front-end and back-end (firebase-functions and nuxt serverMiddleware)
      • types-module: has all shared types (enums, interfaces, constants)
      • handlers-module: has all express handlers. Also, has all backend services like firebase-admin and firestore
    • src: the source of the functions
  • src: nuxt application

``shell script |-- functions | |-- modules | | |-- handlers-module | | |— src
| | -- types-module | |— src
| -- src— src
|— assets
|— components
|— i18n
|— layouts
|— middleware
|— mixin
|— pages
|— plugins
|— server
|— service
|— static
|— store
|— types

  1. ## DETAILED DOCUMENTATION
  2. > Coming soon
  3. ## Features
  4. - [x] nuxtjs - universal mode
  5. - [x] dynamic profile page with username
  6. - [x] typescript
  7. - [x] local npm modules for shared types and functions
  8. - [x] firebase
  9. - [x] firebase-hosting
  10. - [x] firebase-functions
  11. - [x] performance configuration
  12. - [x] the url same as hosting
  13. - [x] dynamic sitemap
  14. - [x] send notification to user devices
  15. - [x] firebase-storage
  16. - [x] profile photo
  17. - [x] cover photo
  18. - [x] upload single validated image
  19. - [x] firestore
  20. - [x] user collection
  21. - [x] firebase-auth
  22. - [x] firebase-auth password
  23. - [x] register
  24. - [x] login
  25. - [x] forget-password
  26. - [x] reset-password
  27. - [x] send verification code
  28. - [x] processing display when the button clicked
  29. - [x] verify action with mail verification code
  30. - [x] update password
  31. - [x] firebase-auth google
  32. - [x] firebase-auth twitter
  33. - [x] firebase-auth facebook
  34. - [x] link/unlink password authenticator
  35. - [x] set password
  36. - [x] link/unlink google authenticator
  37. - [x] link/unlink twitter authenticator
  38. - [x] link/unlink facebook authenticator
  39. - [x] remember me
  40. - [x] user custom claims
  41. - [x] messaging (FCM)
  42. - send push notification
  43. - listen push notification
  44. - [x] token
  45. - save deviceToken on login
  46. - remove device token on logout
  47. - [x] buefy
  48. - [x] nuxt-i18n
  49. - [x] English
  50. - [x] Turkish
  51. - [x] vee-validate
  52. - [x] integration with nuxt-i18n
  53. - [x] custom validation for image
  54. - [x] switch language by queryParam `lang`
  55. - [x] SEO
  56. - [x] Google meta
  57. - [x] Facebook meta
  58. - [x] Twitter card meta
  59. - [x] redirect to next url after login
  60. - [x] custom loading component
  61. - [x] image
  62. - [x] lazy load (vue-lazyload)
  63. - [x] crop with cropperjs
  64. - [x] lightbox with buefy/bulma
  65. - [x] hover button on profile photo
  66. - [x] square/round background image
  67. - [x] privacy
  68. - [x] Account Privacy: Make a profile public/private for other authenticated users
  69. - [x] Followers Privacy: Even if authenticated users cannot see the followers
  70. - [x] Following Privacy: Even if authenticated users cannot see the following
  71. - [x] custom error page - simple
  72. - [x] global notification
  73. - [x] toaster notification
  74. - [x] tooltips
  75. - [x] force logout if token is invalid
  76. - [x] dotenv
  77. - [x] rxJS
  78. - [x] share on social
  79. - [x] facebook
  80. - [x] twitter
  81. - [x] whatsapp
  82. - [x] email
  83. - [x] sms
  84. - [x] uuid
  85. - [x] slug
  86. - [x] better formatting
  87. - [x] tslint
  88. - [x] eslint
  89. - [x] linting before `build`
  90. - [x] backend contracts in an NPM package
  91. Have a look [Trello Board](https://trello.com/b/6JN23G7A/boiler-plate) for more coming functionality
  92. ## Prepare for build
  93. ### firebase configuration
  94. #### create project
  95. create a firebase project on https://console.firebase.google.com/
  96. #### update `.firebaserc`
  97. update `.firebaserc` with the project created/owned by you
  98. > If you already have a project you can use it too.
  99. #### firebase credentials file
  100. > This configuration is necessary for nuxt `serverSiddle`, If you use firebase-functions skip this step.
  101. - export the credentials files from your firebase project.
  102. - copy the file to `server/config/firebase-admin-credentials.json`
  103. #### provider config
  104. #### password
  105. - https://firebase.google.com/docs/auth/web/password-auth
  106. #### google
  107. - https://firebase.google.com/docs/auth/web/google-signin
  108. #### twitter
  109. - https://firebase.google.com/docs/auth/web/twitter-login
  110. ##### facebook
  111. - https://www.robinwieruch.de/firebase-facebook-login
  112. - https://firebase.google.com/docs/auth/web/facebook-login
  113. - https://hackernoon.com/vue-nuxt-firebase-auth-database-ssr-example-tutorial-facebook-login-setup-authentication-starter-app-a6dfde0133fc
  114. #### action configurations
  115. TBD
  116. - - https://firebase.google.com/docs/auth/custom-email-handler
  117. #### development env
  118. create a `development` branch and use that branch for development. Create a new project on firebase and setup `development` branch with the new firebase project
  119. > don't confuse yourself to work on multi-environment in one repository/branch
  120. #### more: TBD
  121. ### dotenv
  122. create `.env` file with below content or rename `.env.template` file
  123. ```.env
  124. WEBSITE_URL=https://nuxt-ts-firebase-auth-ssr.firebaseapp.com
  125. # axios config
  126. #API_URL=http://localhost:3000/api
  127. #API_URL=http://localhost:5000/api
  128. API_URL=https://nuxt-ts-firebase-auth-ssr.firebaseapp.com/api
  129. # firebase config
  130. FIREBASE_API_KEY= ***
  131. FIREBASE_AUTH_DOMAIN= ***
  132. FIREBASE_DATABASE_URL= ***
  133. FIREBASE_PROJECT_ID= ***
  134. FIREBASE_STORAGE_BUCKET= ***
  135. FIREBASE_MESSAGING_SENDER_ID= ***
  136. FIREBASE_APP_ID= ***
  137. FIREBASE_MEASUREMENT_ID= ***

Build & Run & Deploy

the root package.json has been created to manage build and deployment easily.

install dependencies (not npm install or npm i )

  1. $ npm run install

deploy

This command builds and deploys firebase-functions from functions and firebase-hosting from src

  1. $ firebase deploy

run locally with firebase

The following command prepares what are necessary to run the application locally. It builds src and function and generates the public folder.

  1. $ npm run build

and then

  1. $ firebase serve

you will see the links as output of the command

for local development

hosting on local and api on firebase

Firstly, deploy functions to firebase

  1. $firebase deploy --only functions:apiApp

and then

be sure the API_URL configured as firebase-functions like API_URL=https://nuxt-ts-firebase-auth-ssr.firebaseapp.com/api

  1. cd src
  2. npm run dev

hosting and APIs on local

It is possible to run the project as just a nuxt application. With the following instructions, firebase-function is never be in use

Ignore functions, just work on src

enable nuxt serverMiddleware in src/nuxt.config.ts
  1. serverMiddleware: [
  2. '~/server/api',
  3. '~/server/sitemap'
  4. ],
update .env
  1. API_URL=https://localhost:3000/api
and run
  1. cd src
  2. npm run dev

references

Contribution

Please feel free to send a pull request. Welcome :)

  • you see a mistake ( excepted, totally my mistake :) )
  • you know a better/best practice
  • you can add more functionality
  • you found a bug
  • you think you have time to fix/implement a card from Trello Board

hints

localization

change language

strategy: ‘no_prefix’,

  1. changeLocale() {
  2. this.$i18n.setLocale(this.$i18n.locale === 'en' ? 'tr' : 'en')
  3. }

for the other strategy

  1. <nuxt-link :to="switchLocalePath('en')">English</nuxt-link>
  2. <nuxt-link :to="switchLocalePath('tr')">Turkish</nuxt-link>

Errors and fixes

nuxt Failed to execute ‘appendChild’ on ‘Node’: This node type does not support this method.

add client-only tag

  1. <client-only>
  2. ...
  3. </client-only>

npm dependency fixes

To list outdated libraries

  1. npm install -g npm-check-updates

to update the outdated libraries

  1. ncu -u
  2. npm install