Ionicにログイン機能を実装する為、
(Flicher Blog様の実装方法)
を参考にコードを書きブラウザでテストしたのですが、会員登録の処理を送ると404エラーが出てバックエンドと接続が出来ません。どこを改善すれば実装できますでしょうか。
POST http://ドメイン/laravel-auth-passport/auth/register 404 (Not Found)
エラーに関係すると思われるコード
auth.service.ts
TypeScript
1import { HttpClient, HttpHeaders } from '@angular/common/http'; 2import { Injectable } from '@angular/core'; 3import { tap } from 'rxjs/operators'; 4import { NativeStorage } from '@ionic-native/native-storage/ngx'; 5import { EnvService } from './env.service'; 6import { User } from '../models/user'; 7 8@Injectable({ 9 providedIn: 'root' 10}) 11export class AuthService { 12 isLoggedIn = false; 13 token:any; 14 15 constructor( 16 private http: HttpClient, 17 private storage: NativeStorage, 18 private env: EnvService, 19 ) { } 20 21 login(email: String, password: String) { 22 return this.http.get(this.env.API_URL + 'auth/login', 23 {email: email, password: password} 24 ).pipe( 25 tap(token => { 26 this.storage.setItem('token', token) 27 .then( 28 () => { 29 console.log('Token Stored'); 30 }, 31 error => console.error('Error storing item', error) 32 ); 33 this.token = token; 34 this.isLoggedIn = true; 35 return token; 36 }), 37 ); 38 } 39 register(fName: String, lName: String, email: String, password: String) { 40 return this.http.post(this.env.API_URL + 'auth/register', 41 {fName: fName, lName: lName, email: email, password: password} 42 ) 43 } 44 logout() { 45 const headers = new HttpHeaders({ 46 'Authorization': this.token["token_type"]+" "+this.token["access_token"] 47 }); 48 return this.http.get(this.env.API_URL + 'auth/logout', { headers: headers }) 49 .pipe( 50 tap(data => { 51 this.storage.remove("token"); 52 this.isLoggedIn = false; 53 delete this.token; 54 return data; 55 }) 56 ) 57 } 58 user() { 59 const headers = new HttpHeaders({ 60 'Authorization': this.token["token_type"]+" "+this.token["access_token"] 61 }); 62 return this.http.get<User>(this.env.API_URL + 'auth/user', { headers: headers }) 63 .pipe( 64 tap(user => { 65 return user; 66 }) 67 ) 68 } 69 getToken() { 70 return this.storage.getItem('token').then( 71 data => { 72 this.token = data; 73 if(this.token != null) { 74 this.isLoggedIn=true; 75 } else { 76 this.isLoggedIn=false; 77 } 78 }, 79 error => { 80 this.token = null; 81 this.isLoggedIn=false; 82 } 83 ); 84 } 85}
env.service.ts
TypeScript
1import { Injectable } from '@angular/core'; 2 3@Injectable({ 4 providedIn: 'root' 5}) 6export class EnvService { 7 API_URL = 'http://ドメイン/laravel-auth-passport/'; 8 9 constructor() { } 10}

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/20 17:23