質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Firebase

Firebaseは、Googleが提供するBasSサービスの一つ。リアルタイム通知可能、並びにアクセス制御ができるオブジェクトデータベース機能を備えます。さらに認証機能、アプリケーションのログ解析機能などの利用も可能です。

Angular

Angularは、JavaScriptフレームワークです。AngularJSの後継であり、TypeScriptベースで実装されています。機能ごとに実装を分けやすく、コードの見通しが良いコンポーネント指向です。

Firebase Authentication

Firebase Authenticationは、Firebaseを利用したユーザーの認証機能です。バックエンドサービス、SDK、アプリでのユーザー認証に使用できるUIライブラリが用意されています。

TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

Authentication

Authentication(認証)は正当性を認証する為の工程です。ログイン処理等で使われます。

Q&A

2回答

2491閲覧

Angularでfirebaseのauthメソッドが使用できない

magatamaamagata

総合スコア4

Firebase

Firebaseは、Googleが提供するBasSサービスの一つ。リアルタイム通知可能、並びにアクセス制御ができるオブジェクトデータベース機能を備えます。さらに認証機能、アプリケーションのログ解析機能などの利用も可能です。

Angular

Angularは、JavaScriptフレームワークです。AngularJSの後継であり、TypeScriptベースで実装されています。機能ごとに実装を分けやすく、コードの見通しが良いコンポーネント指向です。

Firebase Authentication

Firebase Authenticationは、Firebaseを利用したユーザーの認証機能です。バックエンドサービス、SDK、アプリでのユーザー認証に使用できるUIライブラリが用意されています。

TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

Authentication

Authentication(認証)は正当性を認証する為の工程です。ログイン処理等で使われます。

0グッド

0クリップ

投稿2021/03/18 13:47

エラー内容

Tuyano SYODA氏のAngular超入門のP375でgoogleアカウントで認証してログインする機能を作る部分があります。
以下のtsファイルで各authの行で

Property 'auth' does not exist on type 'AngularFireAuth'.

というエラーが出ます。

調査

(https://github.com/angular/angularfire/issues/2409)
以下でauthを消せば行けるよみたいなことが書いてあったのでauthを削除したのですが、GoogleAuthProvider()と.displayNameとimport { auth } from 'firebase/app';
がエラーで
イメージ説明
のようになります。どうしたら認証がうまくいくでしょうか。
よろしくお願いします。

html

1<div class="container"> 2 <h1>material works!</h1> 3 <div> 4 <p>{{message}}</p> 5 <button mat-raised-button (click)="login()">login</button> 6 <button mat-raised-button (click)="logout()">logout</button> 7 <p>USER: {{currentUser}}</p> 8 <table> 9 <tr> 10 <th>Name</th> 11 <th>Mail</th> 12 <th>Age</th> 13 </tr> 14 <tr *ngFor="let item of data"> 15 <td>{{ item['name'] }}</td> 16 <td>{{ item['mail'] }}</td> 17 <td>{{ item['age'] }}</td> 18 </tr> 19 </table> 20 </div> 21</div> 22

ts

1import { Component, OnInit } from '@angular/core'; 2import { AngularFirestore } from '@angular/fire/firestore'; 3import * as firebase from "firebase"; 4import { AngularFireAuth } from '@angular/fire/auth'; 5import { auth } from 'firebase/app'; 6 7 8@Component({ 9 selector: 'app-fire', 10 templateUrl: './fire.component.html', 11 styleUrls: ['./fire.component.css'] 12}) 13export class FireComponent implements OnInit { 14 message:string = 'people data.'; 15 data:any; 16 17 constructor(private db:AngularFirestore, public afAuth: AngularFireAuth) { } 18 19 ngOnInit() { 20 this.access(); 21 } 22 23 access() { 24 this.db.collection('people') 25 .valueChanges() 26 .subscribe(value=>{ 27 this.data = value; 28 }, 29 error=>{ 30 this.message = "(can't get data...)"; 31 this.data = null; 32 }); 33 } 34 35 login(){ 36 let provider = new firebase.auth.GoogleAuthProvider(); 37 this.afAuth.auth.signInWithRedirect(provider) 38 .then((result)=>{ 39 this.access(); 40 }); 41 } 42 43 logout() { 44 this.afAuth.auth.signOut(); 45 this.access(); 46 } 47 48 49 get currentUser() { 50 return this.afAuth.auth != null ? 51 this.afAuth.auth.currentUser != null? 52 this.afAuth.auth.currentUser.displayName : 53 '(not logined.)' : 54 '(not logined.)'; 55 } 56} 57 58
_ _ ____ _ ___ / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _| / △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | | / ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | | /_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___| |___/ Angular CLI: 11.2.4 Node: 14.15.1 OS: darwin x64 Angular: 11.2.5 ... animations, common, compiler, compiler-cli, core, forms ... platform-browser, platform-browser-dynamic, router Ivy Workspace: Yes Package Version --------------------------------------------------------- @angular-devkit/architect 0.1102.4 @angular-devkit/build-angular 0.1102.4 @angular-devkit/core 11.2.4 @angular-devkit/schematics 11.2.4 @angular/cdk 10.2.7 @angular/cli 11.2.4 @angular/fire 6.1.4 @angular/material 10.2.7 @schematics/angular 11.2.4 @schematics/update 0.1102.4 rxjs 6.5.5 typescript 4.1.5

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

firebase.authとしているところをfirebase.default.authにしてください。

投稿2021/05/18 13:48

ichina

総合スコア6

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

firebaseのauthを使用する場合は次のようにfirebase/authをimportする必要があると思いますが、これは記述されていますか?

tsx

1import "firebase/auth";

投稿2021/03/20 13:26

mikan3rd

総合スコア220

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

magatamaamagata

2021/03/20 14:34

ありがとうございます、tsファイルに記述しましたがダメでした。別のファイルでしょうか!?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問