Skip to content

Commit

Permalink
Merge pull request #255 from mia-ajuda/fix/get_id_from_null
Browse files Browse the repository at this point in the history
Atualiza Metodos Depreciados do Firebase
  • Loading branch information
sudjoao authored Oct 5, 2023
2 parents 67e9da8 + 5340bdf commit 6fabb89
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
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

0 comments on commit 6fabb89

Please sign in to comment.