//tips
//smart contract
Board表示の改修。
現在Boardの中身の取得を下記で対応しているので各[id]ページ用に編集する。
</Typography>
{ninja[0]&&
<div>
<Boardedit item={ninja}/>
</div>
}
<br />
下記のように変更。
{ninja[0]&&
<div>
{ninja[0].title}
{ninja[0].time}
</div>
}
{ninja[0].text&&
ninja[0].text.map((item,index) => (
<div item key={index}>
<Typography>{item.index}{item.username}:{item.chat}</Typography>
<Typography>{item.chat}</Typography>
</div>
))}
{Date.now()}もつけたが分かりにくいので、{Date(Date.now())とすることで認識可能にした。
{ninja[0]&&
<div>
<Typography variant="h4" component="h1" color='textSecondary' gutterBottom>
{ninja[0].title}
</Typography>
</div>
}
{ninja[0].text&&
ninja[0].text.map((item,index) => (
<div item key={index}>
<div className={classes.titleback}>
<h2>{index} ◆{item.username}◆{Date(Date.now())}</h2>
<h2 >{item.chat}</h2>
</div>
<br />
</div>
))}
悪くない感じ。usernameも表示させたいので、localStorage.SetItemのタイミングを探す。
まずは/ID/[id]ページ。自身の認証ができた場合に、 localStorage.setItem(‘username’,ninja[0]username)もローカル保存させる。pile.username = data.usernameでusernameはマストになっているのでどこのindexでも取得可能になっている。
if(localStorage.getItem('authhistory')==ninja[0].mail){
setidmailcheck(true)
localStorage.setItem('authuserid',ninja[0].userid)
localStorage.setItem(‘username’,ninja[0]username)
useEffect(() => {
if(localStorage.getItem('authhistory')==ninja[0].mail){
localStorage.setItem('authuserid',ninja[0].userid)
localStorage.setItem('username',ninja[0].username)
}
signInWithEmailAndPassword(auth,email,password)
.then((cred)=>{
//console.log('user loged in:',cred.user)
localStorage.setItem('authhistory',email)
localStorage.setItem('authuserid',ninja[0].userid)
localStorage.setItem('username',ninja[0].username)
次にloginページでの認証。
useEffect(() => {
localStorage.setItem('username',doc.data().username)
また、handleOnAuthIn(eの場合も問題なく取得できた。
サインアップの際に呼ばれる handleOnAuth(eの場合はどうなるか。この時点では自身のusernameを決めていないためmailがusernameとなっている。
下記で登録しておく。
localStorage.setItem('username','username'+docRef.id)
TopページとなるIndexにも同様の処理を行う。authidがセットできる部分にはusernameも一緒にセットするようにしておいた。
localStorage.getItem(‘username’)をBoardの[id]に組み込む。
初期時点のデータベース”username”の登録・編集場所はどこだったか。
最初の初期登録にusernameの設定も加えてしまう。その方がシンプルになりそう。