mirror of
https://github.com/khairul169/vaulterm.git
synced 2026-09-15 17:03:30 +07:00
fix: native gitlab & github login
This commit is contained in:
@@ -22,3 +22,5 @@ expo-env.d.ts
|
||||
!.env.example
|
||||
*.apk
|
||||
*.aab
|
||||
android/
|
||||
ios/
|
||||
|
||||
+40
-39
@@ -1,41 +1,42 @@
|
||||
{
|
||||
"name": "Vaulterm",
|
||||
"slug": "vaulterm",
|
||||
"version": "1.0.0",
|
||||
"orientation": "portrait",
|
||||
"icon": "./assets/images/icon.png",
|
||||
"scheme": "vaulterm",
|
||||
"userInterfaceStyle": "automatic",
|
||||
"newArchEnabled": true,
|
||||
"splash": {
|
||||
"image": "./assets/images/splash.png",
|
||||
"resizeMode": "contain",
|
||||
"backgroundColor": "#ffffff"
|
||||
},
|
||||
"ios": {
|
||||
"supportsTablet": true
|
||||
},
|
||||
"android": {
|
||||
"package": "sh.rul.vaulterm",
|
||||
"adaptiveIcon": {
|
||||
"foregroundImage": "./assets/images/adaptive-icon.png",
|
||||
"backgroundColor": "#ffffff"
|
||||
}
|
||||
},
|
||||
"web": {
|
||||
"bundler": "metro",
|
||||
"output": "single",
|
||||
"favicon": "./assets/images/favicon.png"
|
||||
},
|
||||
"plugins": [
|
||||
"expo-router"
|
||||
],
|
||||
"experiments": {
|
||||
"typedRoutes": true
|
||||
},
|
||||
"extra": {
|
||||
"eas": {
|
||||
"projectId": "3e0112c1-f0ed-423c-b5cf-95633f23f6dc"
|
||||
}
|
||||
"name": "Vaulterm",
|
||||
"slug": "vaulterm",
|
||||
"version": "1.0.0",
|
||||
"orientation": "portrait",
|
||||
"icon": "./assets/images/icon.png",
|
||||
"scheme": "vaulterm",
|
||||
"userInterfaceStyle": "automatic",
|
||||
"newArchEnabled": true,
|
||||
"splash": {
|
||||
"image": "./assets/images/splash.png",
|
||||
"resizeMode": "contain",
|
||||
"backgroundColor": "#ffffff"
|
||||
},
|
||||
"ios": {
|
||||
"supportsTablet": true,
|
||||
"bundleIdentifier": "sh.rul.vaulterm"
|
||||
},
|
||||
"android": {
|
||||
"package": "sh.rul.vaulterm",
|
||||
"adaptiveIcon": {
|
||||
"foregroundImage": "./assets/images/adaptive-icon.png",
|
||||
"backgroundColor": "#ffffff"
|
||||
}
|
||||
}
|
||||
},
|
||||
"web": {
|
||||
"bundler": "metro",
|
||||
"output": "single",
|
||||
"favicon": "./assets/images/favicon.png"
|
||||
},
|
||||
"plugins": [
|
||||
"expo-router"
|
||||
],
|
||||
"experiments": {
|
||||
"typedRoutes": true
|
||||
},
|
||||
"extra": {
|
||||
"eas": {
|
||||
"projectId": "3e0112c1-f0ed-423c-b5cf-95633f23f6dc"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -27,8 +27,9 @@ const api = ofetch.create({
|
||||
throw new Error("Unauthorized");
|
||||
}
|
||||
|
||||
if (error.response._data) {
|
||||
const message = error.response._data.message;
|
||||
const data = error.response._data;
|
||||
if (data) {
|
||||
const message = typeof data === "string" ? data : data?.message;
|
||||
throw new Error(message || "Something went wrong");
|
||||
}
|
||||
},
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
"scripts": {
|
||||
"start": "expo start",
|
||||
"reset-project": "node ./scripts/reset-project.js",
|
||||
"android": "expo start --android",
|
||||
"ios": "expo start --ios",
|
||||
"prebuild": "expo prebuild",
|
||||
"android": "expo run:android",
|
||||
"ios": "expo run:ios",
|
||||
"web": "expo start --web",
|
||||
"test": "jest --watchAll",
|
||||
"lint": "expo lint",
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import React, { useEffect, useMemo } from "react";
|
||||
import { makeRedirectUri, useAuthRequest } from "expo-auth-session";
|
||||
import appConfig from "@/app.json";
|
||||
import { Button } from "tamagui";
|
||||
import { useOAuthCallback } from "../hooks";
|
||||
import { useServerConfig } from "@/hooks/useServerConfig";
|
||||
import { scheme } from "@/app.json";
|
||||
|
||||
const LoginGithubButton = () => {
|
||||
const { data: clientId } = useServerConfig("github_client_id");
|
||||
@@ -20,7 +20,7 @@ const LoginGithubButton = () => {
|
||||
{
|
||||
clientId: clientId,
|
||||
scopes: ["identity"],
|
||||
redirectUri: makeRedirectUri({ scheme: appConfig.scheme }),
|
||||
redirectUri: makeRedirectUri({ scheme, path: "auth/login" }),
|
||||
},
|
||||
discovery
|
||||
);
|
||||
@@ -28,7 +28,7 @@ const LoginGithubButton = () => {
|
||||
useEffect(() => {
|
||||
if (response?.type === "success") {
|
||||
const { code } = response.params;
|
||||
oauth.mutate(code);
|
||||
oauth.mutate({ code });
|
||||
}
|
||||
}, [response]);
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import React, { useEffect, useMemo } from "react";
|
||||
import { useAuthRequest } from "expo-auth-session";
|
||||
import { makeRedirectUri, useAuthRequest } from "expo-auth-session";
|
||||
import { Button } from "tamagui";
|
||||
import { useOAuthCallback } from "../hooks";
|
||||
import { useServerConfig } from "@/hooks/useServerConfig";
|
||||
import { scheme } from "@/app.json";
|
||||
|
||||
const LoginGitlabButton = () => {
|
||||
const { data: clientId } = useServerConfig("gitlab_client_id");
|
||||
@@ -19,8 +20,7 @@ const LoginGitlabButton = () => {
|
||||
{
|
||||
clientId,
|
||||
scopes: ["read_user"],
|
||||
// redirectUri: makeRedirectUri({ scheme: appConfig.scheme }),
|
||||
redirectUri: "http://localhost:8081",
|
||||
redirectUri: makeRedirectUri({ scheme, path: "auth/login" }),
|
||||
},
|
||||
discovery
|
||||
);
|
||||
|
||||
@@ -45,14 +45,17 @@ export const useRegisterMutation = () => {
|
||||
|
||||
export const useOAuthCallback = (type: string) => {
|
||||
return useMutation({
|
||||
mutationFn: async (params: { code: string; verifier?: string }) => {
|
||||
const res = await api(`/auth/oauth/${type}/callback`, { params });
|
||||
mutationFn: async (body: { code: string; verifier?: string }) => {
|
||||
const res = await api(`/auth/${type}`, { body, method: "POST" });
|
||||
const { data } = loginResultSchema.safeParse(res);
|
||||
if (!data) {
|
||||
throw new Error("Invalid response!");
|
||||
}
|
||||
return data;
|
||||
},
|
||||
onError: (err) => {
|
||||
console.log(err);
|
||||
},
|
||||
onSuccess(data) {
|
||||
authStore.setState({ token: data.sessionId });
|
||||
router.replace("/");
|
||||
|
||||
Reference in New Issue
Block a user