Skip to content

Commit

Permalink
add auto youtube embeding and set expiration properly for jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
Seania committed Jul 5, 2022
1 parent f9f9bda commit e32fd94
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 40 deletions.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "co",
"version": "0.0.1",
"scripts": {
"dev": "svelte-kit dev --port 60000",
"dev": "svelte-kit dev --host --port 60000",
"build": "svelte-kit build",
"start": "node run.js",
"package": "svelte-kit package",
Expand All @@ -17,6 +17,7 @@
"devDependencies": {
"@playwright/test": "^1.22.2",
"@sveltejs/adapter-auto": "next",
"@types/cheerio": "^0.22.31",
"@types/js-cookie": "^3.0.2",
"@types/lodash-es": "^4.17.6",
"@types/secure-random": "^1.1.0",
Expand Down Expand Up @@ -52,6 +53,7 @@
"@tiptap/starter-kit": "2.0.0-beta.190",
"arangojs": "^7.8.0",
"argon2": "^0.28.5",
"cheerio": "1.0.0-rc.12",
"date-fns": "^2.28.0",
"date-fns-tz": "^1.3.5",
"dayjs": "2.0.0-alpha.2",
Expand All @@ -73,7 +75,9 @@
"secure-random": "^1.1.2",
"svelte-body": "^1.3.6",
"svelte-material-icons": "^2.0.2",
"svelte-yt": "^0.1.2",
"svg-loaders": "^0.2.0",
"wysiwyg-editor-node-sdk": "^4.0.12"
"wysiwyg-editor-node-sdk": "^4.0.12",
"youtube-player": "^5.5.2"
}
}
158 changes: 158 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ async function refreshJwt(token: string) {
const user = new User(id);
const {_key, rank} = await user.safeData;
const exp = dayjs().add(15, 'minute').toDate();
const newToken = await user.token('user', {uid: _key, rank}, exp);
const newToken = await user.token('user', {uid: _key, rank});
newToken.setExpiration(exp);
return {newToken: newToken.compact(), user: newToken.body.toJSON()};
}
} catch {
Expand Down
4 changes: 1 addition & 3 deletions src/lib/auth/user/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,11 @@ export class User {
}
}

token(type: 'user' | 'refesh', payload: Rec<unknown> = {}, expire: Date) {
const exp = parseInt((expire.getTime() / 1000).toString())
token(type: 'user' | 'refesh', payload: Rec<unknown> = {}): njwt.Jwt {
return njwt.create({
iss: 'https://ru.hn/',
sub: `user/${this.id}`,
scope: type,
exp,
...payload,
}, key);
}
Expand Down
Loading

0 comments on commit e32fd94

Please sign in to comment.