تثبيت خدمات جوجل فايربيس

المراجع:
https://firebase.google.com/docs/cli?hl=ar#windows-npm

https://firebase.google.com/docs/auth/web/email-link-auth?authuser=0&hl=en#web-version-9

https://firebase.google.com/docs/auth/web/password-auth?hl=en&authuser=0

مراجع الأمان:

https://firebase.google.com/docs/rules/basics?hl=en&authuser=0#realtime-database_2





 تثبيت الحزمة:

sudo npm install -g firebase-tools --force

للمزيد اضغط هنا


تسجيل الدخول على Firebase:

firebase login


إضافة خدمات Firebase إلى مشروعك:

ng add @angular/fire


مشكلة قد تواجهك:

https://stackoverflow.com/questions/71127971/firebase-auth-asking-for-authorization-code-during-installation


مقالة تختصر عليك الكثير:

https://enlear.academy/using-firebase-with-angular-11-3693abe2e808


ملاحظة هامة: يجب إضافة كافة الملفات الموجودة في الرابط أدناه

https://angular.io/guide/build#configure-environment-specific-defaults


------------------------------------------------------------------------------------


دوال تسجيل الدخول:


import { Component } from '@angular/core';
import { Auth, createUserWithEmailAndPassword, getAuth, signInWithEmailAndPassword, signOut } from '@angular/fire/auth';
import { Database, set, ref, update } from '@angular/fire/database';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'al-yahya-dashboard';

constructor(public auth: Auth, public database: Database) {

}

registerUser(value: any) {
createUserWithEmailAndPassword(this.auth, value.email, value.password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
set(ref(this.database, "users/" + user.uid),
{
email: value.email,
fname: value.fname,
user: value.username,
})
alert("لقد تمت إضافة المستخدم بنجاح " + value.username);
// ...
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
// ..
alert(errorMessage);
});
}

signIn(value: any) {
const auth = getAuth();
signInWithEmailAndPassword(this.auth, value.email, value.password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
const date = new Date();
update(ref(this.database, "users/" + user.uid), {
last_login: date
})
alert("user loged in!");
// ...
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;

alert(errorMessage);
});
}


signOut() {
const auth = getAuth();
signOut(auth).then(() => {
//Session destroy
}).catch((error) => {

})
}
}


إعداد:





تعليقات

المشاركات الشائعة من هذه المدونة

ngx-extended-pdf-viewer

how to getting access token for https://fcm.googleapis.com/v1/projects/al-ayahya-co/messages:send for angular and backend nestjs

طريقة تفعيل زر Inline Keyboard في Telegram Bot