@@ -30,8 +30,8 @@ async function authenticateAndCreateJWT(
3030 const oauthUrl = provider === "github"
3131 ? "https://github.com/login/oauth/access_token"
3232 : provider === "gitlab"
33- ? "https://gitlab.com/oauth/token"
34- : null ;
33+ ? "https://gitlab.com/oauth/token"
34+ : null ;
3535
3636 if ( oauthUrl === null ) {
3737 ctx . response . body = "Unsupported provider" ;
@@ -47,14 +47,14 @@ async function authenticateAndCreateJWT(
4747 code,
4848 } ) . toString ( )
4949 : provider === "gitlab"
50- ? new URLSearchParams ( {
51- client_id : id ,
52- client_secret : secret ,
53- code,
54- grant_type : "authorization_code" ,
55- redirect_uri : `${ frontend } /login` ,
56- } ) . toString ( )
57- : "" ;
50+ ? new URLSearchParams ( {
51+ client_id : id ,
52+ client_secret : secret ,
53+ code,
54+ grant_type : "authorization_code" ,
55+ redirect_uri : `${ frontend } /login` ,
56+ } ) . toString ( )
57+ : "" ;
5858
5959 const resp = await fetch ( rootUrl . toString ( ) , {
6060 method : "POST" ,
@@ -69,7 +69,7 @@ async function authenticateAndCreateJWT(
6969
7070 ctx . response . headers . set ( "Access-Control-Allow-Origin" , "*" ) ;
7171
72- if ( status . matchedCount == 1 ) {
72+ if ( status . matchedCount == 1 || status . upsertedId !== undefined ) {
7373 const id_jwt = await createJWT ( provider , userId ) ;
7474 Sentry . captureMessage ( "User " + userId + " logged in" , "info" ) ;
7575 ctx . response . body = id_jwt ;
@@ -97,7 +97,7 @@ async function handleJwtAuthentication(ctx: Context) {
9797 const provider = document . provider ;
9898 const user = await checkJWT ( provider , jwt_token ) ;
9999 const apiKey = generateApiKey ( user )
100- ctx . response . body = { user , apiKey} ;
100+ ctx . response . body = { user , apiKey } ;
101101}
102102
103103export { githubAuth , gitlabAuth , handleJwtAuthentication } ;
0 commit comments