wip
This commit is contained in:
parent
347a5680ae
commit
ba40952a09
7 changed files with 99 additions and 49 deletions
|
@ -2,4 +2,20 @@ import * as React from 'react';
|
|||
import * as ReactDOM from 'react-dom';
|
||||
import { App } from './App';
|
||||
|
||||
// cookieにトークンが入ってたらlocalStorageに移し替える
|
||||
const token = document.cookie
|
||||
.split('; ')
|
||||
.find(row => row.startsWith('token'))
|
||||
?.split('=')[1];
|
||||
|
||||
console.log(document.cookie);
|
||||
console.log(token);
|
||||
|
||||
if (token) {
|
||||
localStorage['token'] = token;
|
||||
// 今の所はcookieをトークン以外に使用しないため全消去する
|
||||
// もしcookieの用途が増えるのであればここを良い感じに書き直す必要がある
|
||||
document.cookie = '';
|
||||
}
|
||||
|
||||
ReactDOM.render(<App/>, document.getElementById('app'));
|
27
src/frontend/pages/index.session.tsx
Normal file
27
src/frontend/pages/index.session.tsx
Normal file
|
@ -0,0 +1,27 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
import { Header } from '../components/Header';
|
||||
|
||||
export const IndexSessionPage: React.VFC = () => {
|
||||
const token = localStorage['token'];
|
||||
const [session, setSession] = useState<Record<string, any> | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetch(`//${location.host}/api/v1/session`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
},
|
||||
}).then(s => s.json())
|
||||
.then(setSession);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header>
|
||||
<article className="mt-4">
|
||||
おかえりなさい、{session?.username}さん。
|
||||
</article>
|
||||
</Header>
|
||||
</>
|
||||
);
|
||||
};
|
|
@ -1,41 +1,10 @@
|
|||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import { Ranking } from '../components/Ranking';
|
||||
import { LoginForm } from '../components/LoginForm';
|
||||
import { DeveloperInfo } from '../components/DeveloperInfo';
|
||||
import { HashtagTimeline } from '../components/HashtagTimeline';
|
||||
import { Header } from '../components/Header';
|
||||
import { IndexSessionPage } from './index.session';
|
||||
import { IndexWelcomePage } from './index.welcome';
|
||||
|
||||
export const IndexPage: React.VFC = () => {
|
||||
return (
|
||||
<>
|
||||
<Header>
|
||||
<article className="mt-4">
|
||||
<p>
|
||||
Misskeyは楽しいものです。気がついたら1日中入り浸っていることも多いでしょう。
|
||||
</p>
|
||||
<p>
|
||||
さあ、今すぐみす廃アラートをインストールして、あなたの活動を把握しよう。
|
||||
</p>
|
||||
</article>
|
||||
<LoginForm />
|
||||
</Header>
|
||||
<article className="xarticle card ghost">
|
||||
<div className="body">
|
||||
<h1 className="mb-1">みす廃ランキング</h1>
|
||||
<Ranking limit={10} />
|
||||
<Link to="/ranking">全員分見る</Link>
|
||||
</div>
|
||||
</article>
|
||||
<article className="xarticle mt-4 row">
|
||||
<div className="col-12 pc-6 card ghost">
|
||||
<div className="body"><DeveloperInfo/></div>
|
||||
</div>
|
||||
<div className="col-12 pc-6 card ghost">
|
||||
<div className="body"><HashtagTimeline hashtag="misshaialert"/></div>
|
||||
</div>
|
||||
</article>
|
||||
</>
|
||||
);
|
||||
const token = localStorage.getItem('token');
|
||||
|
||||
return token ? <IndexSessionPage /> : <IndexWelcomePage />;
|
||||
};
|
||||
|
|
37
src/frontend/pages/index.welcome.tsx
Normal file
37
src/frontend/pages/index.welcome.tsx
Normal file
|
@ -0,0 +1,37 @@
|
|||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
import { Ranking } from '../components/Ranking';
|
||||
import { LoginForm } from '../components/LoginForm';
|
||||
import { DeveloperInfo } from '../components/DeveloperInfo';
|
||||
import { HashtagTimeline } from '../components/HashtagTimeline';
|
||||
import { Header } from '../components/Header';
|
||||
|
||||
export const IndexWelcomePage: React.VFC = () => {
|
||||
return (
|
||||
<>
|
||||
<Header>
|
||||
<article className="mt-4">
|
||||
<p>Misskeyは楽しいものです。気がついたら1日中入り浸っていることも多いでしょう。</p>
|
||||
<p>さあ、今すぐみす廃アラートをインストールして、あなたの活動を把握しよう。</p>
|
||||
</article>
|
||||
<LoginForm />
|
||||
</Header>
|
||||
<article className="xarticle card ghost">
|
||||
<div className="body">
|
||||
<h1 className="mb-1">みす廃ランキング</h1>
|
||||
<Ranking limit={10} />
|
||||
<Link to="/ranking">全員分見る</Link>
|
||||
</div>
|
||||
</article>
|
||||
<article className="xarticle mt-4 row">
|
||||
<div className="col-12 pc-6 card ghost">
|
||||
<div className="body"><DeveloperInfo/></div>
|
||||
</div>
|
||||
<div className="col-12 pc-6 card ghost">
|
||||
<div className="body"><HashtagTimeline hashtag="misshaialert"/></div>
|
||||
</div>
|
||||
</article>
|
||||
</>
|
||||
);
|
||||
};
|
|
@ -252,7 +252,7 @@ async function login(ctx: Context, user: Record<string, unknown>, host: string,
|
|||
|
||||
const misshaiToken = await updateUsersMisshaiToken(u);
|
||||
|
||||
ctx.cookies.set('token', misshaiToken, { signed: true });
|
||||
ctx.cookies.set('token', misshaiToken, { signed: false, httpOnly: false });
|
||||
|
||||
// await ctx.render('logined', { user: u });
|
||||
ctx.redirect('/');
|
||||
|
|
|
@ -25,11 +25,12 @@ export default (): void => {
|
|||
routePrefix: '/api/v1',
|
||||
defaultErrorHandler: false,
|
||||
currentUserChecker: async ({ request }: Action) => {
|
||||
const authorization: string | null = request.headers['Authorization'];
|
||||
const { authorization } = request.header;
|
||||
if (!authorization || !authorization.startsWith('Bearer ')) return null;
|
||||
|
||||
const token = authorization.split(' ')[1];
|
||||
return getUserByMisshaiToken(token);
|
||||
const token = authorization.split(' ')[1].trim();
|
||||
const user = await getUserByMisshaiToken(token);
|
||||
return user;
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ html
|
|||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
body
|
||||
body.dark
|
||||
#app: .loading Loading...
|
||||
|
||||
script(src=`/assets/fe.${version}.js`)
|
||||
script(src=`/assets/fe.${version}.js` async defer)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue