Hello, I'm getting a CORS Missing Allow Origin alo...
# support-questions-legacy
s
Hello, I'm getting a CORS Missing Allow Origin along with NS_ERROR_DOM_BAD_URI when calling the signin endpoint from my custom UI and can't figure out what I'm doing wrong (More details in the thread)
My login page is on
http://localhost:5173/login
and the backend is running on
http://localhost:4000
Frontend code:
Copy code
js
SuperTokens.init({
  appInfo: {
    apiDomain: 'http://localhost:4000',
    apiBasePath: "/auth",
    appName: "MyApp",
  },
  recipeList: [
    Session.init(),
    ThirdPartyEmailPassword.init(),
  ],
  enableDebugLogs: !!import.meta.env.VITE_SUPERTOKENS_DEBUG,
});
and
Copy code
js
emailPasswordSignIn({
      formFields: [{
        id: "email",
        value: formData.email
      }, {
        id: "password",
        value: formData.password
      }]
    })
Backend code:
Copy code
go
apiBasePath := "/auth"
websiteBasePath := "/login"
err := supertokens.Init(supertokens.TypeInput{
        Debug: env.SuperTokensDebug != "",
        Supertokens: &supertokens.ConnectionInfo{
            // https://try.supertokens.com is for demo purposes. Replace this with the address of your core instance (sign up on supertokens.com), or self host a core.
            ConnectionURI: "https://my-instance.aws.supertokens.io",
            APIKey:        "my-api-key",
        },
        AppInfo: supertokens.AppInfo{
            AppName:         "MyApp",
            APIDomain:       "http://localhost:4000",
            WebsiteDomain:   "http://localhost:5173",
            APIBasePath:     &apiBasePath,
            WebsiteBasePath: &websiteBasePath,
        },
        RecipeList: []supertokens.Recipe{
            thirdpartyemailpassword.Init(&tpepmodels.TypeInput{
                Providers: []tpmodels.ProviderInput{
                    {
                        Config: tpmodels.ProviderConfig{
                            ThirdPartyId: "google",
                            Clients: []tpmodels.ProviderClientConfig{
                                {
                                    ClientID:     env.GoogleClientID,
                                    ClientSecret: env.GoogleClientSecret,
                                },
                            },
                        },
                    },
                },
            }),
            dashboard.Init(),
        },
    })
and
Copy code
go
type Server struct {
    Router *chi.Mux
}

func (s *Server) MountHandlers() {
    // CORS
    s.Router.Use(cors.Handler(cors.Options{
        AllowedOrigins: []string{"http://localhost:5173"},
        AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
        AllowedHeaders: append([]string{"Content-Type"},
            supertokens.GetAllCORSHeaders()...),
        AllowCredentials: true,
    }))

    // Middlewares
    s.Router.Use(supertokens.Middleware)
}
Am I doing something wrong?
r
whats the output in the console log?
s
console log shows the CORS error
im not 100% whats wrong in your code
s
Got it, thanks for the help. I guess the issue is somewhere else then
Quick question, if my login page is at
http://localhost:5173/login
, then
websiteBasePath := "/login"
is correct, right?
Or is is supposed to be
websiteBasePath := "/"
r
/login is correct
s
Figured it out, I needed to add the session recipe in the backend
12 Views