Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atualiza Metodos Depreciados do Firebase #255

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/services/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const api = axios.create({
api.interceptors.request.use(
async (config) => {
let accessToken = await AsyncStorage.getItem('accessToken');

if (accessToken) {
const user = await firebaseService.getCurrentUser();
if (user && accessToken) {
const expireDate = jwt_decode(accessToken).exp;
const now = Date.now() / 1000;

Expand Down
56 changes: 28 additions & 28 deletions app/src/services/Firebase.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import { initializeApp } from 'firebase/app';
import {
getAuth,
signInWithEmailAndPassword,
sendEmailVerification,
sendPasswordResetEmail,
getIdToken,
signOut,
signInWithCredential,
onAuthStateChanged,
} from 'firebase/auth';
import Constants from 'expo-constants';
import authConfig from '../config/authmiaajuda-firebase';
import authConfigDev from '../config/authmiaajuda-firebase-dev';
Expand All @@ -9,58 +18,49 @@ class FirebaseService {
const env = Constants.manifest.releaseChannel;
const { apiKey, authDomain, projectId } =
env == 'prod' ? authConfig : authConfigDev;
this.firebase = firebase.initializeApp({
this.app = initializeApp({
apiKey,
authDomain,
projectId,
});
this.auth = getAuth();
}

isEmailVerified() {
return this.firebase.auth().currentUser.emailVerified;
return this.auth.currentUser.emailVerified;
}

async login(email, password) {
return await this.firebase
.auth()
.signInWithEmailAndPassword(email, password);
return await signInWithEmailAndPassword(this.auth, email, password);
}

async sendEmailVerification() {
await this.firebase.auth().currentUser.sendEmailVerification();
await sendEmailVerification(this.auth.currentUser);
}

async getUserId() {
return await this.firebase.auth().currentUser?.getIdToken();
return await getIdToken(this.auth.currentUser);
}

async getCurrentUser() {
return this.firebase.auth().currentUser;
return this.auth.currentUser;
}

async resetUserPassword(email) {
await this.firebase.auth().sendPasswordResetEmail(email);
await sendPasswordResetEmail(this.auth, email);
return true;
}
async setPersistence() {
await this.firebase
.auth()
.setPersistence(this.firebase.auth.Auth.Persistence.LOCAL);
}
async getCredentialFacebook(token) {
return await this.firebase.auth.FacebookAuthProvider.credential(token);
}

async signInWithCredential(credential) {
return await this.firebase.auth().signInWithCredential(credential);
}
async getCredentialGoogle(idToken, accessToken) {
return await this.firebase.auth.GoogleAuthProvider.credential(
idToken,
accessToken,
);
return await signInWithCredential(this.auth, credential);
}

async signOut() {
await this.firebase.auth().signOut();
await signOut(this.auth);
}

async onAuthStateChanged(callbackfunction) {
this.firebase.auth().onAuthStateChanged(callbackfunction);
onAuthStateChanged(this.auth, callbackfunction);
}
}

Expand Down