voting without an account redirects to login
This commit is contained in:
parent
c04cf3889e
commit
ce7957e0bf
3 changed files with 11 additions and 4 deletions
|
@ -6,7 +6,7 @@ export async function GET({ url, cookies }) {
|
|||
|
||||
var user = await tokenBackend({token});
|
||||
|
||||
if (!user) return;
|
||||
if (!user) return new Response('fail');
|
||||
|
||||
var id = url.searchParams.get('post');
|
||||
var vote = url.searchParams.get('vote');
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
/** @type {import('./$types').PageLoad} */
|
||||
export async function load({ fetch, params, url }) {
|
||||
var search = url.searchParams;
|
||||
|
@ -7,7 +9,12 @@ export async function load({ fetch, params, url }) {
|
|||
var id = params.post;
|
||||
|
||||
if (voteType) {
|
||||
await fetch(`/api/vote?post=${id}&vote=${voteType}`);
|
||||
var voteRes = await fetch(`/api/vote?post=${id}&vote=${voteType}`);
|
||||
var voteJson = await voteRes.text();
|
||||
|
||||
if (voteJson == 'fail') {
|
||||
throw redirect(302, '/account');
|
||||
}
|
||||
}
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue