Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
b142c04b
authored
Aug 07, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: git
parent
a4c1a049
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
client/src/pages/api/user/account/gitLogin.ts
+6
-6
No files found.
client/src/pages/api/user/account/gitLogin.ts
View file @
b142c04b
...
@@ -17,6 +17,7 @@ type GithubAccessTokenType = {
...
@@ -17,6 +17,7 @@ type GithubAccessTokenType = {
scope
:
string
;
scope
:
string
;
};
};
type
GithubUserType
=
{
type
GithubUserType
=
{
login
:
string
;
email
:
string
;
email
:
string
;
avatar_url
:
string
;
avatar_url
:
string
;
};
};
...
@@ -35,22 +36,22 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
...
@@ -35,22 +36,22 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
throw
new
Error
(
'access_token is null'
);
throw
new
Error
(
'access_token is null'
);
}
}
const
{
const
{
data
}
=
await
axios
.
get
<
GithubUserType
>
(
'https://api.github.com/user'
,
{
data
:
{
email
,
avatar_url
}
}
=
await
axios
.
get
<
GithubUserType
>
(
'https://api.github.com/user'
,
{
headers
:
{
headers
:
{
Authorization
:
`Bearer
${
access_token
}
`
Authorization
:
`Bearer
${
access_token
}
`
}
}
});
});
const
{
login
,
email
,
avatar_url
}
=
data
;
const
username
=
email
||
login
;
try
{
try
{
jsonRes
(
res
,
{
jsonRes
(
res
,
{
data
:
await
loginByUsername
({
username
:
email
,
res
})
data
:
await
loginByUsername
({
username
,
res
})
});
});
}
catch
(
err
:
any
)
{
}
catch
(
err
:
any
)
{
if
(
err
?.
code
===
500
)
{
if
(
err
?.
code
===
500
)
{
jsonRes
(
res
,
{
jsonRes
(
res
,
{
data
:
await
registerUser
({
username
:
email
,
avatar
:
avatar_url
,
res
})
data
:
await
registerUser
({
username
,
avatar
:
avatar_url
,
res
})
});
});
}
}
throw
new
Error
(
err
);
throw
new
Error
(
err
);
...
@@ -71,7 +72,6 @@ export async function loginByUsername({
...
@@ -71,7 +72,6 @@ export async function loginByUsername({
res
:
NextApiResponse
;
res
:
NextApiResponse
;
})
{
})
{
const
user
=
await
User
.
findOne
({
username
});
const
user
=
await
User
.
findOne
({
username
});
console
.
log
(
user
,
username
);
if
(
!
user
)
{
if
(
!
user
)
{
return
Promise
.
reject
({
return
Promise
.
reject
({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment