Yes the bass should most definataly be in the same key as the rest of the song! All the instruments need to be in the same key and move from chord to chord cohesively. One place to start for bass would be to use the root note for each chord in the progression.
For instance, say your chord progression is Am - F - C - G
The main bass notes you would play are A F C G and you can spice it up a little on the transitions to each of those notes.
Another tip I would give is if you are new to theory and writing music, start out writing all of your songs in the key of C. The key of C is good because all the notes in the key of C are the white keys on the piano. So you don't have to worry about the black ones.