feat: better components
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
import { createConnectTransport } from '@connectrpc/connect-web';
|
||||
import { createValidator } from "@bufbuild/protovalidate";
|
||||
import { Code, ConnectError, createClient, type Interceptor } from '@connectrpc/connect';
|
||||
import { AuthService } from '$lib/connect/user/v1/auth_pb';
|
||||
import { UserService } from '$lib/connect/user/v1/user_pb';
|
||||
import { ItemService } from '$lib/connect/item/v1/item_pb';
|
||||
import { goto } from '$app/navigation';
|
||||
import { page } from '$app/state';
|
||||
|
||||
const redirector: Interceptor = (next) => async (req) => {
|
||||
try {
|
||||
@ -11,7 +13,11 @@ const redirector: Interceptor = (next) => async (req) => {
|
||||
} catch (e) {
|
||||
const error = ConnectError.from(e);
|
||||
if (error.code === Code.Unauthenticated) {
|
||||
await goto('/auth');
|
||||
const redirectURL = new URL(page.url);
|
||||
redirectURL.pathname = '/auth';
|
||||
redirectURL.searchParams.append('redir', encodeURIComponent(page.url.pathname + page.url.search));
|
||||
|
||||
await goto(redirectURL);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
@ -25,3 +31,5 @@ const transport = createConnectTransport({
|
||||
export const AuthClient = createClient(AuthService, transport);
|
||||
export const UserClient = createClient(UserService, transport);
|
||||
export const ItemClient = createClient(ItemService, transport);
|
||||
|
||||
export const Validator = createValidator();
|
||||
|
Reference in New Issue
Block a user